hdoj The first place of 2^n 3215 (数学技巧&预处理)
2016-03-01 16:48
405 查看
The first place of 2^n
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 665 Accepted Submission(s): 300
[align=left]Problem Description[/align]
LMY and YY are mathematics and number theory lovers. They like to find and solve interesting mathematic problems together. One day LMY calculates 2n one by one, n=0, 1, 2,… and writes the results on a sheet of paper: 1,2,4,8,16,32,64,128,256,512,1024,……
LMY discovers that for every consecutive 3 or 4 results, there must be one among them whose first digit is 1, and comes to the conclusion that the first digit of 2n isn’t evenly distributed between 1 and 9, and the number of 1s exceeds those of others. YY now
intends to use statistics to prove LMY’s discovery.
[align=left]Input[/align]
Input consists of one or more lines, each line describing one test case: an integer N, where 0≤N≤10000.
End of input is indicated by a line consisting of -1.
[align=left]Output[/align]
For each test case, output a single line. Each line contains nine integers. The ith integer represents the number of js satisfying the condition that 2j begins with i (0≤j≤N).
[align=left]Sample Input[/align]
0
1
3
10
-1
[align=left]Sample Output[/align]
1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 1 0 1 0 0 0 1 0
4 2 1 1 1 1 0 1 0//题意:有多组数据,每组数据是一个数n,当输入为-1时就结束。让你先计算出2^i(0<=i<=n)的值后,然后统计所有的值的第一位数出现的次数。输出:每组输出9个数,分别是1-9出现的次数。//思路:因为题中要求的是n<=10000.所以要计算2^n的数会很大,所以用一个数kk记录每次平方后的第一位数即可。具体看代码:
#include<stdio.h> #include<string.h> #include<algorithm> #define INF 0x3f3f3f3f #define ll long long #define N 10010 using namespace std; int map [11]; int init() { int i,j,k; double kk=1; map[0][1]=1; for(i=1;i<=10000;i++) { for(j=1;j<=9;j++) { map[i][j]=map[i-1][j]; } kk*=2; if(kk>10) kk/=10; map[i][(int)kk]++; } } int main() { init(); int n,i,j; while(scanf("%d",&n)&&n!=-1) { for(i=1;i<9;i++) printf("%d ",map [i]); printf("%d\n",map [9]); } return 0; }
相关文章推荐
- spark streaming kafka1.4.1中的低阶api createDirectStream使用总结
- Maven仓库—Nexus环境搭建及简单介绍
- LeetCode题解:Missing Number
- 【找规律】HDOJ Rikka with Chess 5630
- Spring AOP 动态代理
- Android蓝牙开发介绍
- Android必知必会-Stetho调试工具
- VPI 8.6 安装时遇到的问题及解决
- 51nod1354选数字
- DB2中字符、数字和日期类型之间的转换
- Android必知必会-Stetho调试工具
- Tomcat启动问题汇总
- Rails的HashWithIndifferentAccess
- QQ空间实现(一)—— 展示说说中的评论内容并有相应点击事件
- mac 下利用apache服务器配置项目站点
- Sudoku Solver填数
- Java开发中的23种设计模式详解(转)
- jqgrid实现行拖拽功能
- (转)参加SCRUM中文网CSM认证班的一些感想
- 冒泡排序 回顾