ZOJ 3793 First Digit(数学)

来源:互联网 发布:数据挖掘 预测算法 编辑:程序博客网 时间:2024/05/22 10:53


First Digit

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

Benford's Law, also called the First-Digit Law, refers to the frequency distribution of digits in many (but not all) real-life sources of data. In this distribution, the number 1 occurs as the leading digit about 30% of the time, while larger numbers occur in that position less frequently: 9 as the first digit less than 5% of the time. Benford's Law also concerns the expected distribution for digits beyond the first, which approach a uniform distribution.

This result has been found to apply to a wide variety of data sets, including electricity bills, street addresses, stock prices, population numbers, death rates, lengths of rivers, physical and mathematical constants, and processes described by power laws (which are very common in nature). It tends to be most accurate when values are distributed across multiple orders of magnitude.

A set of numbers is said to satisfy Benford's Law if the leading digit d ∈ {1, ..., 9} occurs with probabilityP(d) = log10(d + 1) - log10(d). Numerically, the leading digits have the following distribution in Benford's Law:

d123456789P(d)30.1%17.6%12.5%9.7%7.9%6.7%5.8%5.1%4.6%

Now your task is to predict the first digit of be, whileb and e are two random integer generated by discrete uniform distribution in [1, 1000]. Your accuracy rate should be greater than or equal to 25% but less than 60%.This is not a school exam, and high accuracy rate makes you fail in this task. Good luck!

Input

There are multiple test cases. The first line of input contains an integer T (about 10000) indicating the number of test cases. For each test case:

There are two integers b and e (1 <= b, e <= 1000).

Output

For each test case, output the predicted first digit. Your accuracy rate should be greater than or equal to 25% but less than 60%.

Sample Input

20206 774133 931420 238398 872277 137717 399820 754997 46377 791295 345375 501102 66695 172462 893509 83920 315418 71644 498508 459358 767

Sample Output

82214212114624972717

Hint


题意:是求b的e次幂的第一位数字,但不是输出100%正确的答案,正确率为25%~60%。


题解:有种做法数直接全部输出1就行了,因为题意说的1的概率为31.1%.

           我的做法是直接算出第一位,然后一般输出ans+1.....

          b^e=(10^k)^e,k*e=x+y,x为k*e的整数部分,y为小数部分,10^y的整数部分就是第一位数


#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#define N 100050using namespace std;int b,e;int main() {    //freopen("test.in","r",stdin);    int t;    cin>>t;   for(int i=1;i<=t;i++) {        scanf("%d%d",&b,&e);        double x=log10(b*1.0)*e;        double y=x-(int)x;        double ans=pow(10.0,y);        int k=(int)ans;        if(i>=t/2)k+=1;        if(k>=10)k=1;        printf("%d\n",k);    }    return 0;}


0 0
原创粉丝点击