zoukankan      html  css  js  c++  java
  • FZU

    /*
      这题主要是想到突破口--每次除以2(我感觉还是思维题,就像我当时做时,就是想不到 T^T)
      然后,用1个奇数和1个偶数举一下例子
      f(7) = f(3) + 1, f(3) = f(1) + 1, f(1) = 1
      f(8) = f(4) + 1, f(4) = f(2) + 1, f(2) = f(1) + 1, f(1) = 1
    */


    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    int main()
    {
    	int t, n;
    	scanf("%d", &t);
    	for (int c = 1; c <= t; c++)
    	{
    		scanf("%d", &n);
    		int res = 0;
    		while (n)
    		{
    			res++;
    			n /= 2;
    		}
    		printf("Case %d: %d
    ", c, res);
    	}
    	return 0;
    }

    //以及这题还想明白除以2以后,就可以用对数去做了,注意每次除以2,除以log2n次,最后还要加上f(1),如下
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    
    int main()
    {
    	int t, n;
    	scanf("%d", &t);
    	for (int c = 1; c <= t; c++)
    	{
    		scanf("%d", &n);
    		int res = (int)(log(n) / log(2) + 1);
    		printf("Case %d: %d
    ", c, res);
    	}
    	return 0;
    }


  • 相关阅读:
    设计模式-抽象工厂模式
    设计模式-工厂方法模式
    设计模式-单例
    java集合-补充HashMapJDK1.8
    java多线程-线程池
    java-阻塞队列
    java多线程-信号量
    java多线程-读写锁
    java多线程-锁
    Ubuntu下编译Poco库
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789537.html
Copyright © 2011-2022 走看看