HDU 3215 The first place of 2^n(数论-其他)
来源:互联网 发布:淘宝入驻条件2017 编辑:程序博客网 时间:2024/06/06 10:07
The first place of 2^n
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
Source
2009 Shanghai Network Contest Host by DHU
Recommend
zhuweicong
题目大意:
解题思路:题目大意就是计算2^0到2^n这n个数首位为1的次数,2的次数,...9的次数。
参考代码:log10,纯数学。注意精度误差。
X = pow(10, i * log10(2.0) - int(i * log10(2.0)));自己想为什么。
#include <iostream>#include <cstring>#include <cmath>using namespace std;const int MAXN = 10010;const double eps = 1e-10;int first[MAXN], cnt[10], n;void init() { for (int i = 0; i <= 10000; i++) { first[i] = int(pow(10, i * log10(2.0) - int(i * log10(2.0))) + eps); }}void solve() { memset(cnt, 0, sizeof(cnt)); for (int i = 0; i <= n; i++) { cnt[first[i]]++; } for (int i = 1; i <= 9; i++) { if (i > 1) cout << " "; cout << cnt[i]; } cout << endl;}int main() { ios::sync_with_stdio(false); init(); while (cin >> n && n != -1) { solve(); } return 0;}
0 0
- HDU 3215 The first place of 2^n(数论-其他)
- HDU 3215 The first place of 2^n (数论-水题)
- 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(计算2^0到2^n首位出现的1,2,3...9的个数)
- hdoj The first place of 2^n 3215 (数学技巧&预处理)
- 一道让我纠结的水题——上海邀请赛The first place of 2^n
- HDU 2674 N!Again (数论-其他)
- Hdu 4596 Yet another end of the world(数论)
- HDU-4596 Yet another end of the world (数论)
- hdu 2674 (数论,N!)
- HDU 2674 N!Again (数论-水题)
- HDU 2802 F(N)(数论)
- HDU 2674 N!Again (数论)
- hdu 2674 N!Again(数论,水题)
- java编程之Noncompliant; %n should be used in place of \n to produce the platform-specific line separato
- (数论)HDU 4596 Yet another end of the world题解
- HDU 5381 The sum of gcd(数论+莫队算法)
- Alcatel/阿尔卡特OT-995 root教程_方法
- 欧奇 A12 root教程_方法
- 泛泰Vega IM-A650S root教程_方法
- Samsung/三星GALAXY NOTE(I9220/至尊版) root教程_方法
- 使用 jQuery Mobile 与 HTML5 开发 Web App —— 12 jQuery Mobile 页面事件与 deferred
- HDU 3215 The first place of 2^n(数论-其他)
- Huawei/华为GL07S root教程_方法
- android屏幕分辨率适配
- hdu 1290 献给杭电五十周年校庆的礼物
- Samsung/三星GALAXY S5 G9008W(移动/4G版) root教程_方法
- 也谈if语句
- MIUI/小米手机1S (电信官翻版) root教程_方法
- 使用 jQuery Mobile 与 HTML5 开发 Web App —— 13 jQuery Mobile 方法上
- 图像处理之 YUYV422 To OpenCV IplImage