现在的位置: 首页 > 综合 > 正文

一道让我纠结的水题——上海邀请赛The first place of 2^n

2013年12月28日 ⁄ 综合 ⁄ 共 1554字 ⁄ 字号 评论关闭

Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

[Submit]  
[Go
Back
]   [Status]

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.

 

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.

 

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 2jbegins with i (0≤j≤N).
 

Sample Input

0 1 3 10 -1
 

Sample Output

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
 

[Submit]  
[Go
Back
]   [Status]


我一开始以为有规律可循,没想到后面的根本不符合,一时大意铸成大错!
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int Max = 10005;
int map[Max][10];

int main(){
    int i, j, num;
    double w = 1;//唉使用double类型进行处理。。巧妙啊(换成__int64就会WA,我要死了)
    map[0][1] = 1;
    for(i = 1; i <= 10002; i ++){
        for(j=1;j<=9;j++){
            map[i][j] = map[i-1][j];
        }
        w*= 2;
        if(w > 10) w /= 10;
        map[i][(int)(w)] ++;
    }
    while(cin>>num){
        if(num==-1) break;
        cout<<map[num][1];
        for(i=2;i<=9;i ++){
            cout<<" "<<map[num][i];
        }

            cout<<endl;
    }
    return 0;
}

抱歉!评论已关闭.