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} 两个循环.
每首歌有一个积分值,1thinking特别喜欢玩Queen的 'Another One Bites The Dust',每次他一定会玩这首歌。现在1thinking知道这首歌是积分值 第二大 的歌曲。他想知道他喜欢的歌所在的循环的分数和。 现在给出N首歌的难度值,求1tthinking游戏一次所获得的期望积分和是多少?
举个例子,当前有三首歌,积分为1、2、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 分。

Input
第一个整数 T, 数据的组数。
对于每组数据,第一行,整数 N,表示排列的长度。
第二行,N个整数 V1, V2, ..., VN, 每首歌的积分值。(0 ≤ Vi < 231)
Output
对于每组数据,一个浮点数,期望积分(精确到 0.000001)。
Sample Input
3
1 2 3
Sample Output
HINT
Source
题解:
只要把除了第二大的元素地位看成相同的,那么不妨把每个数看成他们的ave,然后我们就可以枚举第二大元素所在的置换群的大小用组合数搞一下。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
ll c[][];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for1(i,)
{
c[i][]=c[i][i]=;
for1(j,i-)c[i][j]=c[i-][j]+c[i-][j-];
}
int cs=read();
while(cs--)
{
int n=read();ll a[];
for1(i,n)a[i]=read();
sort(a+,a+n+);
double t=,ans=a[n-];
for1(i,n)if(i!=n-)t+=a[i];
t/=(double)(n-);
for1(i,n-)ans+=c[n-][i]*((double)i*t+a[n-]);
printf("%.6f\n",ans/((ll)<<(n-)));
}
return ;
}
BZOJ2293: 【POJ Challenge】吉他英雄的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )
虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...
- 2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 553 Solved: 230[Submit][ ...
随机推荐
- Sidebar Enhancements使用说明
SideBarEnhancements是Sublime侧栏文件与文件夹的增强工具 Version: 2015.5.27 通过使用Sumbime Text3安装包工具(Package Control,快 ...
- iOS 动画基础
原文:http://www.cnblogs.com/lujianwenance/p/5733846.html 今天说一下有关动画的基础,希望能帮助到一些刚接触iOS动画或者刚开始学习iOS的同学, ...
- 坑爹CF April Fools Day Contest题解
H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show som ...
- Stay Hungry, Stay Foolish--2005斯坦福大学05年毕业演讲
转自http://www.cnblogs.com/daizhj/articles/1493813.html 斯蒂夫•保罗•乔布斯(Steve Paul Jobs,1955年2月24日出生-)是蘋果電腦 ...
- 一次ora-1113 记录
记录博客园的第一天,今天在电脑前发呆,突然感觉自己记忆越来越差,近年来随着工作力度的加强,感觉自己越来越力不从心,问题重复的出现.感觉自己应该去记录点什么了,随选择了用写博客的方式记录一下.第一天先记 ...
- gitlab ActionView::Template::Error (undefined method `[]' for nil:NilClass): 500错误
Started GET "/mygroup/myproject/tree/master/MyDirectory" for 127.0.0.1 at 2014-10-22 22:42 ...
- MySQL事务隔离级别初探
MySQL有四种隔离级别,分别是: READ UNCOMMITTED(未提交读) READ COMMITTED(提交读) REPEATABLE READ (可重复读) SERIALIZABLE(可串行 ...
- 韩顺平_JAVA_视频教程_下载(打开迅雷,直接复制链接地址即可下载)
ed2k://|file|韩顺平.循序渐进学.java.从入门到精通.第0讲-开山篇.avi|37021064|f4fb2fb3db938a642146ccc8f0935fed|h=ao2k3ep7p ...
- linq 动态排序
/// <summary> /// 排序 /// </summary> /// <typeparam name="T"></typepar ...
- SimpleMembership: The future of membership for ASP.NET
http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal- ...