2134: 單選錯(cuò)位 Time Limit: 10 Sec Memory Limit: 259 MB Description Input n很大,為了避免讀入耗時(shí)太多,輸入文件只有5個(gè)整數(shù)參數(shù)n, A, B, C, a1,由上交的程序產(chǎn)生數(shù)列a。下面給出pascal/C/C++的讀入語句和產(chǎn)生序列的語句(默認(rèn)從標(biāo)準(zhǔn)輸入讀入): // for pascal readln(n,A,B,C,q[1]); for i:=2 to n do q[i] := (int64(q[i-1]) * A + B) mod 100000001; for i:=1 to n do q[i] := q[i] mod C + 1; // for C/C++ scanf(“%d%d%d%d%d”,&n,&A,&B,&C,a+1); for (int i=2;i<=n;i++) a[i] = ((long long)a[i-1] * A + B) % 100000001; for (int i=1;i<=n;i++) a[i] = a[i] % C + 1; 選手可以通過以上的程序語句得到n和數(shù)列a(a的元素類型是32位整數(shù)),n和a的含義見題目描述。 Output 輸出一個(gè)實(shí)數(shù),表示gx期望做對(duì)的題目個(gè)數(shù),保留三位小數(shù)。 Sample Input 3 2 0 4 1 Sample Output 1.167 【樣例說明】 a[] = {2,3,1} 正確答案 gx的答案 做對(duì)題目 出現(xiàn)概率 {1,1,1} {1,1,1} 3 1/6 {1,2,1} {1,1,2} 1 1/6 {1,3,1} {1,1,3} 1 1/6 {2,1,1} {1,2,1} 1 1/6 {2,2,1} {1,2,2} 1 1/6 {2,3,1} {1,2,3} 0 1/6 共有6種情況,每種情況出現(xiàn)的概率是1/6,gx期望做對(duì)(3+1+1+1+1+0)/6 = 7/6題。(相比之下,lc隨機(jī)就能期望做對(duì)11/6題) 【數(shù)據(jù)范圍】 對(duì)于100%的數(shù)據(jù) 2≤n≤10000000, 0≤A,B,C,a1≤100000000
/*原諒我一開始沒看懂題目.這題還是比較簡(jiǎn)單的說.i有a[i]選法,i+1有a[i+1]選法,ai與ai+1相等時(shí)得1分,求期望.貢獻(xiàn)=1,所以最后的期望值就等于概率值嘍.然后會(huì)發(fā)現(xiàn)每個(gè)題目都是獨(dú)立的.case 1:a[i]>=a[i+1] 有a[i]種選法,a[i+1]/a[i]的概率選到1 2 3 ---a[i+1].并有1/a[i+1]的概率選對(duì),總概率為1/a[i].case 2:a[i]<a[i+1] 同理.*/#include<iostream>#include<cstdio>#define MAXN 10000001#define LL long longusing namespace std;LL a[MAXN],n,A,B,C;double ans;LL read(){ LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar(); return x*f; }double slove1(LL x,LL y){ double tot=double(1/double(max(x,y))); return tot;}void slove(){ a[0]=a[n]; for(int i=1;i<=n;i++) ans+=slove1(a[i-1],a[i]); return ;}int main(){ n=read(),A=read(),B=read(),C=read(),a[1]=read(); for(int i=2;i<=n;i++) a[i]=(a[i-1]*A+B)%100000001; for(int i=1;i<=n;i++) a[i]=a[i]%C+1; slove();新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注