Test instructions: For a sequence, two people take turns to play the game, the first person to play first, it will exchange options adjacent and exchange, the second after playing, he has 0 each. 5 of the opportunity to add one or more in reverse order, the first person always want to play the least number of steps, then the number of steps expected.
Problem-solving idea: It turned out to be a math problem crying.
Problem Solving Code:
1 //File name:351b.cpp2 //Author:darkdream3 //Created time:2015 March 25 Wednesday 10:34 48 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - #defineMAXN 3005 - using namespacestd; - intA[MAXN]; - intTREE[MAXN]; in intLowbit (intx) - { to returnX &-x; + } - intN; the voidUpdateintx) * { $ while(x <=N)Panax Notoginseng { -TREE[X] + =1; theX + =lowbit (x); + } A } the intGetsum (intx) + { - intAns =0 ; $ while(x >=1 ) $ { -Ans + =Tree[x]; -X-=lowbit (x); the } - returnans;Wuyi } the intMain () { -scanf"%d",&n); Wu intNX =0 ; - for(intI=1; I <= N;i + +) About { $scanf"%d",&a[i]); -NX + = I-getsum (A[i])-1; - //printf ("%d\n", NX); - Update (a[i]); A } + if(NX%2==1 ) theprintf"%LF",2*nx-1.0); - Elseprintf"%LF",2.0*NX); $ the return 0; the}
View Code
Codeforces 351B Jeff and Furik