[hdu 5051]2014上海网络赛 Fraction 数学 Benford's law/打表找规律
来源:互联网 发布:微信扫码群发营销软件 编辑:程序博客网 时间:2024/05/14 03:54
Fraction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 239 Accepted Submission(s): 55
Problem Description
Given a number n, and a geometric progression ai = b * qi, i ≥ 0, what is the fraction of the elements of that progression with decimal notation that has the decimal notation of n as prefix ?
More formally, if ci out of the first i elements of the progression start with n in decimal notation, you need to find the limit. It is guaranteed that the limit always exists.
For example, n = 7, b = 1, q = 2. About 5.799% of all powers of two start with 7. (the smallest one is 246 = 70368744177664)
More formally, if ci out of the first i elements of the progression start with n in decimal notation, you need to find the limit. It is guaranteed that the limit always exists.
For example, n = 7, b = 1, q = 2. About 5.799% of all powers of two start with 7. (the smallest one is 246 = 70368744177664)
Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each case contains three integers n,b and q. (1 ≤ n, b, q ≤ 1000)
Each case contains three integers n,b and q. (1 ≤ n, b, q ≤ 1000)
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then output one floating number – the sought fraction. Round your answer to the 5th decimal place.
Sample Input
27 1 21 1 1
Sample Output
Case #1: 0.05799Case #2: 1.00000
Source
2014 ACM/ICPC Asia Regional Shanghai Online
题目大意
给定n,b,q
设ai = b * q^i
求当m趋近于无穷时,a1~am之中前缀为n的概率
解题思路
因为保证一定收敛,试着打表找一下规律
后来发现n取定后 不论b,q为何值都会基本收敛到一个数值,模拟100000项误差也不是很大
最后发现关于取定的n ans=(lg((n+1)/n))
特判一下q=1,10,100,1000的情况(相当于只向后面添加0,或者保持b不变)
想到了代码就水了,比赛的时候卡了多次边界= =
#include <cstdio>#include <cmath>using namespace std;int main(){ int T,ca=0; scanf("%d",&T); while (T--) { int n,b,q; scanf("%d%d%d",&n,&b,&q); double nn=n,bb=b,qq=q;/* 以下为打表 bb=log10(bb); printf("Case #%d: ",++ca); int ans=0; for (int i=1;i<=1000000;i++) { bb+=log10(q); if ((int) (pow(10.0,(bb-((int)(bb))))+(int)(log10(double (n)))==n) if (bb>bb-((int)(bb))+(int)(log10(n))) ans++; } printf("%.5f\n",((double)ans)/1000000); 打表结束 */ double r; if (q==10||q==100||q==1000) if (b==n||b/10==n||b/100==n||b/1000==n||b*10==n||b*100==n||b*1000==n) r=1; else r=0; else if (q==1) if (b==n||b/10==n||b/100==n||b/1000==n) r=1; else r=0; else r=log10((double)(n+1)/double(n)); printf("%.5f\n",r); } return 0;}
0 0
- [hdu 5051]2014上海网络赛 Fraction 数学 Benford's law/打表找规律
- 神奇的Benford law (目前尚未有人能给出Benford law的充分条件和严密的数学证明)
- 20140930 【 数论 -- 本福特定律 】 2014-上海区域赛-网络预选赛 hdoj 5051 Fraction
- HDU 5052 Yaoge’s maximum profit(树链剖分+线段树,2014上海网络赛1011)
- 【数学】 HDOJ 5051 Fraction
- CodeForces-630 B. Moore's Law【数学】
- 多校-HDU 5351 MZL's Border 数学规律
- HDU 5621 KK's Point(数学+规律题)
- HDU 6154 CaoHaha's staff(【数学规律题】)
- 2015上海网络赛 HDU 5478 Can you find it 数学
- HDU 6189 Law of Commutation 2017ACM-ICPC 广西邀请赛 (打表找规律)
- hdu 4342 数学规律
- hdu 5587(数学规律)
- hdu 2086 数学规律
- 语言统计学三大定律:Zipf law,Heaps law和Benford law
- hdu 5050 Divided Land---2014acm上海赛区网络赛
- HDU 5044 Tree(LCA ,2014上海网络赛1003)
- hdu 5045 Contest--2014acm上海赛区网络赛
- HDU 4362 Dragon Ball 线段树
- android虚拟机
- Android应用程序相关的文件目录详解
- leetcode-Anagrams
- Andorid——ubuntu下的 NDK / JNI
- [hdu 5051]2014上海网络赛 Fraction 数学 Benford's law/打表找规律
- android应用进程
- js 监听表单提交事件,防止表单重复提交
- java二叉树
- android ART虚拟机
- Java常用开源类库
- 第七周项目2-体重检测系统
- 【Hibernate】最简单的Hibernate工程——账号注册系统
- Dictionary这个对象在ASP还是很useful