#P3175. [HAOI2015] 按位或
[HAOI2015] 按位或
Description
Initially, you have the number . Every second, you randomly choose a number from and apply bitwise OR with your current number (C++, C: |, Pascal: or). The probability of choosing number is . It is guaranteed that , . Find the expected number of seconds until your current number becomes .
Input Format
The first line contains , the number of elements. The second line contains numbers; the -th number is the probability of selecting .
Output Format
Output a single number representing the answer. An absolute or relative error not exceeding is accepted. If there is no solution, output INF.
2
0.25 0.25 0.25 0.25
2.6666666667
Hint
For of the testdata, .
The following is the SPJ source code.
//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;
}
Translated by ChatGPT 5
京公网安备 11011102002149号