原题:http://acm.hdu.edu.cn/showproblem.php?pid=2178
思路:
这个题的题干描述很差,正确的意思是:你要猜到的最大的数字m,即在1到m间的每一个数,你都能在n次内把它猜出来。求m
所以说在最坏的情况下,在1到m间,你最多只要猜log2(m+1)次,所以m=2^n-1,即猜n次,你能猜到的最大的数为2^n-1。这道题就是这么简单
源代码:
#include <cstdio> #include <cmath> int t,n,ans=0; int main() { scanf("%d",&t); for (int i=1;i<=t;i++) { ans=0; scanf("%d",&n); ans=pow(2,n)-1; printf("%d\n",ans); } }