BZOJ2293: 【POJ Challenge】吉他英雄

2293: 【POJ Challenge】吉他英雄

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 80  Solved: 59
[Submit][Status]

Description

 

1tthinking 特別喜歡玩‘guitar hero’。 如今有 N (2 ≤ N ≤ 50) 首歌在這個遊戲中,他們被標爲 1 到 N。 遊戲會隨機把歌曲分組 P。 更詳細的說, 對於 P = <P1, P2, ... PN>, 遊戲會在第 i 首以後播放第 Pi首。 所以這 N 首歌會造成幾個循環來播放. 舉個例子, 若是 N = 3, P = <2, 1, 3> 咱們獲得了 {1, 2} 和 {3} 兩個循環.php

每首歌有一個積分值,1thinking特別喜歡玩Queen的 'Another One Bites The Dust',每次他必定會玩這首歌。如今1thinking知道這首歌是積分值 第二大 的歌曲。他想知道他喜歡的歌所在的循環的分數和。 如今給出N首歌的難度值,求1tthinking遊戲一次所得到的指望積分和是多少?ios

舉個例子,當前有三首歌,積分爲一、二、3。1tthinking老是會選擇積分爲2的歌曲。一共可能的排列有6種: <1, 2, 3>, <1, 3, 2>, <2, 1, 3>, <2, 3, 1>, <3, 1, 2> and <3, 2, 1>。 1tthinking分別會等機率選擇 {2}, {2, 3}, {1, 2}, {1, 2, 3}, {1, 2, 3}, {2} 得到 2, 5, 3, 6, 6, 2 分。平都可以得到 (2 + 5 + 3 + 6 + 6 + 2) / 6 = 24 / 6 = 4.0000 分。ide

Input

 

 

第一個整數 T, 數據的組數。ui

對於每組數據,第一行,整數 N,表示排列的長度。spa

第二行,N個整數 V1, V2, ..., VN, 每首歌的積分值。(0 ≤ Vi < 231)code


Output

對於每組數據,一個浮點數,指望積分(精確到 0.000001)。blog

Sample Input

1
3
1 2 3

Sample Output


4.000000

HINT

Source

題解:遊戲

只要把除了第二大的元素地位當作相同的,那麼不妨把每一個數當作他們的ave,而後咱們就能夠枚舉第二大元素所在的置換羣的大小用組合數搞一下。。。ip

代碼:get

 1 #include<cstdio>
 2 
 3 #include<cstdlib>
 4 
 5 #include<cmath>
 6 
 7 #include<cstring>
 8 
 9 #include<algorithm>
10 
11 #include<iostream>
12 
13 #include<vector>
14 
15 #include<map>
16 
17 #include<set>
18 
19 #include<queue>
20 
21 #include<string>
22 
23 #define inf 1000000000
24 
25 #define maxn 100000
26 
27 #define maxm 500+100
28 
29 #define eps 1e-10
30 
31 #define ll long long
32 
33 #define pa pair<int,int>
34 
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36 
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38 
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40 
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42 
43 #define mod 1000000007
44 
45 using namespace std;
46 
47 inline int read()
48 
49 {
50 
51     int x=0,f=1;char ch=getchar();
52 
53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
54 
55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
56 
57     return x*f;
58 
59 }
60 ll c[100][100];
61 
62 int main()
63 
64 {
65 
66     freopen("input.txt","r",stdin);
67 
68     freopen("output.txt","w",stdout);
69     for1(i,50)
70     {
71         c[i][0]=c[i][i]=1;
72         for1(j,i-1)c[i][j]=c[i-1][j]+c[i-1][j-1];
73     }
74 
75     int cs=read();
76     while(cs--)
77     {
78         int n=read();ll a[100];
79         for1(i,n)a[i]=read();
80         sort(a+1,a+n+1);
81         double t=0,ans=a[n-1];
82         for1(i,n)if(i!=n-1)t+=a[i];
83         t/=(double)(n-1);
84         for1(i,n-1)ans+=c[n-1][i]*((double)i*t+a[n-1]);
85         printf("%.6f\n",ans/((ll)1<<(n-1)));
86     }
87 
88     return 0;
89 
90 } 
View Code
相關文章
相關標籤/搜索