猜数字
来源:互联网 发布:mac pro 重新安装系统 编辑:程序博客网 时间:2024/06/06 08:36
Problem Description
A有1数m,B来猜.B每猜一次,A就说"太大","太小"或"对了" 。 <br>问B猜n次可以猜到的最大数。 <br>
Input
第1行是整数T,表示有T组数据,下面有T行 <br>每行一个整数n (1 ≤ n ≤ 30) <br>
Output
猜n次可以猜到的最大数<br>
Sample Input
2<br>1<br>3
Sample Output
1<br>7<br>
简单题意:
猜数字的题目,求出猜N次可以猜到的最大数。
解题思路形成过程:
猜n次,能猜到的最大数字为pow(2,n)-1。所以从1到pow(2,n)-1,在n次都可以猜出来。
感想:
透过文字看本质,想透了,代码实现以及算法也就清楚了。
AC代码:
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
int n,t;
while(scanf("%d",&t)!=EOF)
{
for(int i=0;i<t;i++)
{
cin>>n;
printf("%d\n",(int)pow(2,n)-1);
}
}
return 0;
}
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
int n,t;
while(scanf("%d",&t)!=EOF)
{
for(int i=0;i<t;i++)
{
cin>>n;
printf("%d\n",(int)pow(2,n)-1);
}
}
return 0;
}
0 0
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- 猜数字
- el表达式
- 自考总结之信息资源管理
- Java NIO系列教程(二)
- 移动办公应用的需求分析讨论
- sublime 中的快捷键以及使用技巧
- 猜数字
- 移动终端播放器的探索历程
- Android组件之服务---Service
- 不容易系列之一
- 真分页和假分页
- ScrollView嵌套ListView
- googlesamples/android-topeka学习笔记(三)-----undone
- poj 2774 Long Long Message(后缀数组)
- 程序员养生