题意:对于一个序列,两个人轮流玩游戏 ,第一个人先玩,它会交换选择相邻的并且交换,第二个后玩,他有0各有.5的机会使得逆序数加一或者加一,序列单调递增时结束,第一个人总想要玩得步数最小,那么步数的期望值是多少。

解题思路:原来是个数学题 哭了。

解题代码:

 1 // File Name: 351b.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年03月25日 星期三 10时34分48秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 #define maxn 3005
26 using namespace std;
27 int a[maxn]; 
28 int tree[maxn];
29 int lowbit(int x)
30 {
31    return x & -x ; 
32 }
33 int n ;
34 void update(int x)
35 {
36     while(x <= n)
37     {
38        tree[x] += 1;
39        x += lowbit(x);
40     }
41 }
42 int  getsum(int x)
43 {
44   int ans = 0 ; 
45   while(x >= 1 )
46   {
47      ans += tree[x];
48      x -= lowbit(x);
49   }
50   return ans ;
51 }
52 int main(){
53     scanf("%d",&n);
54     int nx = 0 ; 
55     for(int i= 1;i <= n;i ++)
56     {
57       scanf("%d",&a[i]);
58       nx += i - getsum(a[i]) - 1;
59       //printf("%d\n",nx);
60       update(a[i]);
61     }
62     if(nx % 2 == 1 )
63         printf("%lf",2*nx-1.0);
64     else printf("%lf",2.0*nx);
65          
66 return 0;
67 }
View Code

 

posted on 2015-03-29 16:30  dark_dream  阅读(205)  评论(0编辑  收藏  举报