ACM第二次练习—1008

来源:互联网 发布:网络教育文凭含金量 编辑:程序博客网 时间:2024/05/16 05:20

题意:A有1数m,B来猜.B每猜一次,就说太大,太小或对了。问B猜n次可以猜到的最大数。 

思路:猜n次,你能猜到的最大数的数为2^n-1.我们也可认为,在数1到2^n-1间,我们都可以在n次内猜出来。

感想:也许这个题也能用二分,但是我想不出来。

代码:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
 int n,t;
 while(scanf("%d",&t)!=EOF)
 {
  while(t--&&scanf("%d",&n))
  {
   printf("%d\n",(int)pow(2,n)-1);
  }
 }
 return 0;
}

0 0
原创粉丝点击