Test instructions: There are three cups, one of which has a coin, each time the left or right of the cup and the middle of the Cup exchange, asked the n operation, the probability of a coin in the middle is how much.
Analysis: Write on the paper every time left, middle, and right to have coins probability, write to 7 or 8 probably can see the law.
The general formula found at the beginning is: F (n) = (f (n-1) +f (n-2))/2, then the conversion program f (N) = (1-f (n-1))/2, and then convert it into f (n) =an/bn form.
And then see the law and can see bn=2^ (n-1),
When n is odd: a= (2^ (n-1)-1)/3,
When n is even: a= (2^ (n-1)-2)/3+1.
/************************************************author:D arktongcreated time:2016/7/15 19:27:41File Name: e.cpp*************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<cstdlib>#include<ctime>#defineINF 0x3f3f3f3f#defineESP 1e-9typedefLong LongLL;using namespacestd;Const intMOD = 1e9+7;Const intMAXN =100000+ -; LL AA[MAXN]; ll Quick_mod (ll t,ll N) {ll ans=1; while(n) {if(n&1) ans=ans*t%MOD; T=t*t%MOD; N>>=1; } returnans;} ll Inv (ll x) {returnQuick_mod (x, mod-2);}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);LL inv3 = INV (3); LL Inv2= INV (2); intN, f=1, f2=0; scanf ("%d", &N); for(intI=1; i<=n;++i) {scanf ("%lld", &Aa[i]); if(aa[i]%2==0) f=0; if(aa[i]>1) f2=1; } if(!F2) {Puts ("0/1"); return 0; } LL b=1, a=1; b=quick_mod (2, aa[1]); for(intI=2; i<=n;++i) {b=Quick_mod (b, aa[i]); } b=b*inv2%MOD; if(f) {a= (b-1+MOD) *inv3%MOD); } Else{a= (b-2+MOD) *inv3%mod+1)%MOD; } printf ("%lld/%lld\n", A, b); return 0;}
Codeforces 696c-please