刚开始你有一个数字 ,每一秒钟你会随机选择一个 的数字,与你手上的数字进行或(C++,C 的 |,pascal 的 or)操作。选择数字 的概率是 。保证 , 。问期望多少秒后,你手上的数字变成 。
|
or
第一行输入 表示 个元素,第二行输入 个数,第 个数表示选到 的概率。
仅输出一个数表示答案,绝对误差或相对误差不超过 即可算通过。如果无解则要输出 INF。
INF
2 0.25 0.25 0.25 0.25
2.6666666667
对于 的数据,。
以下为 spj 源代码。
//liuchenrui #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #define AC {fclose(fstd),fclose(fuser);return 0;} #define WA {fclose(fstd),fclose(fuser);return 1;} #define PE {fclose(fstd),fclose(fuser);return 5;} #define eps 1e-6 int main(int const argc, char*const argv[]){ FILE *fstd,*fuser; fstd=fopen(argv[2],"r"); fuser=fopen(argv[3],"r"); //fstd=fopen("x1.in","r"); //fuser=fopen("x2.in","r"); char s[30],t[30]; if(fscanf(fuser,"%s",s+1)==-1)WA; fscanf(fstd,"%s",t+1); if(s[1]=='I' && t[1]=='I')AC; if(s[1]=='I' || t[1]=='I')WA; double p,q; sscanf(s+1,"%lf",&p); sscanf(t+1,"%lf",&q); if(fabs(p-q)<eps)AC else{ if(fabs(p-q)/q<eps)AC; if(fabs(q-p)/q<eps)AC; if(fabs(p-q)/p<eps)AC; if(fabs(q-p)/p<eps)AC; } WA; }