hdoj The first place of 2^n 3215 (数学技巧&预处理)
来源:互联网 发布:钢窗 知乎 编辑:程序博客网 时间:2024/06/08 16:58
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
Problem Description
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.
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.
Input
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.
End of input is indicated by a line consisting of -1.
Output
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).
Sample Input
01310-1
Sample Output
1 0 0 0 0 0 0 0 01 1 0 0 0 0 0 0 01 1 0 1 0 0 0 1 04 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 10010using namespace std;int map[N][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[n][i]);printf("%d\n",map[n][9]);}return 0;}
0 0
- hdoj The first place of 2^n 3215 (数学技巧&预处理)
- HDU/HDOJ 3215 The first place of 2^n
- Hdu 3215 The first place of 2^n (对数)
- HDU 3215 The first place of 2^n (数论-水题)
- HDU 3215 The first place of 2^n(数论-其他)
- HDU 3215 The first place of 2^n(计算2^0到2^n首位出现的1,2,3...9的个数)
- 一道让我纠结的水题——上海邀请赛The first place of 2^n
- hdoj the Sum of Cube 5053 (简单数学)
- hdoj 5053 the Sum of Cube [数学 立方求和]
- HDOJ 4596 Yet another end of the world【数学】
- hdoj The sum problem 2058 (数学等差公式&技巧转换)
- java编程之Noncompliant; %n should be used in place of \n to produce the platform-specific line separato
- The first step of Java[2]
- The first step of JavaEE[2]
- Nothing in the world can take the place of Persistence
- tack a place first
- Mai-a-hee mai-a-hu. I got the first place and the second place in goole page ranking.
- 【技巧】HDOJ N!Again 2674
- Fragment的使用
- [MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据
- POJ 1016 Numbers That Count(水~)
- 浏览器JS文件缓存问题
- 获取Android手机短信中心号码
- hdoj The first place of 2^n 3215 (数学技巧&预处理)
- Tesseract-OCR 训练中文
- Android 日常开发总结的技术经验 60 条
- IOS多线程及队列的使用
- SPOJ 16549 QTREE6 - Query on a tree VI
- CSS 外边距(margin)重叠及防止方法
- ListView小知识点总结
- iOS中常用到的全局变量
- Android源码阅读工具——在Ubuntu下使用Source Insight