Http://codeforces.com/problemset/problem/351/B
Test instructions: Two person takes turns game, the initiator exchanges adjacent two number, the hand first throws the coin, the positive on the left big right small change, opposite right big left small to change, randomly finds a logarithm, until the entire sequence rises position, asks the minimum desired step number.
Idea: Because the first person each time will reduce a pair of reverse, then the hand will be 50% to reduce a pair, 50% increase a pair, we put two people together is:
50% reverse is unchanged, 50% decreases by 2
f[i]=f[i]*0.5+f[i-2]*0.5
Figure out is f[i]=f[i-2]+4, initial value: F[0]=0,f[1]=1
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <algorithm>5#include <iostream>6 intn,a[3005],c[3005];7 intf[3005*3005];8 intRead () {9 intt=0, f=1;CharCh=GetChar ();Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} One while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} A returnt*F; - } - intLowbit (intx) { the returnx& (-x); - } - voidAddintx) { - for(inti=x;i;i-=lowbit (i)) { +c[i]++; - } + } A intAskintx) { at intres=0; - for(inti=x;i<=n;i+=lowbit (i)) { -res+=C[i]; - } - returnRes; - } in intMain () { -N=read ();intans=0; to for(intI=1; i<=n;i++) a[i]=read (); + for(intI=1; i<=n;i++) ans+=ask (A[i]), add (A[i]); -f[0]=0; f[1]=1; the for(intI=2; i<=ans;i++) f[i]=f[i-2]+4; *printf"%.6f\n",(Double) F[ans]); $}
Codeforces 351B Jeff and Furik