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][ ...
随机推荐
- 版本控制:集中式 vs 分布式
集中式 CVCS的版本库集中存放在中央服务器,而工作时都是用自己的电脑,所以要先从中央服务器取得最新的版本,然后工作完后再将自己的代码推送给中央服务器. CVS:最早的.开源.免费.由于自身设计的问题 ...
- Objective-C description的用法
description类似于.net/java ToString()方法的用途. 假设有一个CTPerson类, - (NSString *)description { return @"d ...
- Apache配置命令
Apache的主配置文件: 1.DocumentRoot——指定网站的根目录 提示:该目录必须存在.目录上不能有汉字或空格. 2.DirectoryIndex (1)描述:设置网站的默认首页文件.访问 ...
- Xcode 7 支持http请求info.plist设置
由于iOS9改用更安全的https,为了能够在iOS9中正常使用http发送网络请求,请在"Info.plist"中进行如下配置,否则影响SDK的使用. 1.找到项目中的 Info ...
- 【实习记】2014-08-29算法学习Boyer-Moore和最长公共子串(LCS)
昨天的问题方案一:寻找hash函数,可行性极低.方案二:载入内存,维护成一个守护进程的服务.难度比较大.方案三:使用前5位来索引,由前3位增至前5位唯一性,理论上是分拆记录扩大100倍,但可以 ...
- zabbix 配置
终于把zabbix配置好了.可能还有待优化 我主要参考了几个链接 http://lnmp.org/install.html 一键安装lnmp http://blog.unix178.com/2 ...
- get share button count
class shareCount { private $url,$timeout; function __construct($url,$timeout=10) { $this->url=raw ...
- absolute之实现居中的三种方式
居中思想可以由很多方式实现,这篇文章采用absolute实现:由传统方式开始到absolute独立使用方式 方式一:传统方式,父容器relateive,子元素absolute,然后left:50%,再 ...
- php 文件上传的基本方法
基本思路:1.HTML表单中 form中的enctype必为enctype="multipart/form-data",method = post 设置提交数据中的type = f ...
- BOM 子对象,history,location,screen
history:包括浏览器访问过的 url 属性:返回浏览器访问过的历史记录数 方法:back(); forward(); go(number) location:包含当前 url 的相关信息 属性: ...