给定一个数n
和b和q,会生成一个数组 b*q;
问这个数组中n为前缀的概率。
n为前缀的概率即为n的使用频率。。
(可还有n不是前缀的时候呢。)
可是在百度百科上看了这么一段话
您住宅地址号码是以a 1开始的吗?根据一个奇特的数学定律统计,约三分之一的住宅号码是以1作为其首个数字的。其它许多几乎没有任何共通性的地区也有相同的情况:比如道琼斯指数的历史数据、个人电脑中文件储存的大小排列顺序、世界主要河流的长度、报纸头版头条的数字及其它许多事情。
这就是赤裸裸的当前缀了。。。。
于是乎就用吧。。
如果q不为 1 10 100 1000,就能看做 从自然界的样本。。
1 sprintf的应用。挺6
2 就是第一数学定律了、
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
/* ****************** */
/*第一数学定律。
*/
typedef long long LL;
double fun(LL n,LL x)//判断
{
char s1[50], s2[50];
int i;
sprintf(s1, "%I64d", n);//将式子转化为字符串,
sprintf(s2, "%I64d", x);
for(i = 0; s1[i]; i ++)//s1是子串。
if(s2[i]=='\0' || s1[i] != s2[i])
return 0.0;
return 1.0;
}
int main()
{
int cas, ee = 0;
int n, b, q;
double ans;
scanf("%d", &cas);
for(int tt=1;tt<=cas;tt++)
{
scanf("%d%d%d", &n, &b, &q);
if(q==1||q==10||q==100||q==1000)//因为最多3次方,所以下面三次方
ans=fun(1ll*n,1ll*q*q*q*b);
else
ans=log((n+1.0)/n)/log(10.0);//第一数学定律公式。自行百度。。
printf("Case #%d: %.5lf\n", tt, ans);
}
return 0;
}