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][ ...
随机推荐
- ios 可变参数(va_list,va_start,va_end)
例如:UIAlertView的init方法中的otherButtonTitles:(NSString *)otherButtonTitles, ...等多个可变参数. ios实现传递不定长的多个参数的 ...
- oracle 11g卸载方法
在网上查看了很多卸载oracle11g的方法,但是感觉都太复杂了,没有使用,最后查看了很多资料,得到一种比较简单,而且能完全卸载的方法: 在根目录下运行c:\app\Administrator\pro ...
- jeesite 经常出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL解决思路
本来jeesite是用的maven,但是我开发的项目用这个框架没用maven, 经常报这个错,我能用的办法就是将springmvc—web.jar包删掉,然后重新添加
- 时间处理得到UTC时间
在工作过程遇到了时间处理的问题,因为需要统一将时间处理按照utc时间进行处理,因此,不能简单的通过系统运行直接得到时间的毫秒数,这样会在不同时区得到的值是不同的. import java.text.P ...
- 在类成员函数后面加const
在看开源代码时,经常会看到在类的成员函数后面加const,之前了没有太关注过,近来闲来无事,就想起这件事,网上查了一下,大概明白了是怎么回事,这里引用CSDN愽文里的段话:“编译器会自动给每一个函数加 ...
- IOS 学习日志 2015-3-16
Objective--C 一 关键字 self 相当于java中的this,但是又有不同 它即可一代替对象,也可以代替类, 也就是说它既可以用在静态方法中又可以用在动态方法中. super 相当于父类 ...
- ASP.Net大文件上传组件详解
首先右键单击网站根目录,在弹出的快捷菜单中,选择"添加引用"菜单项,弹出"添加引用",切换到"浏览"找到组件的Dll文件"Best ...
- js判断是否全是相同的字符串
isSameStr("aa2a") //不都是相同的字符 function isSameStr(str){ var tem=0; for(var i=0;i<str.leng ...
- SQLite学习第02天:数据类型
参考资料:http://www.w3cschool.cc/sqlite/sqlite-data-types.html 在SQLite中,数据类型的概念看起来很模糊,刚开始接触感觉跟C语言提供的数据类型 ...
- 如何判断list中是否包含某个元素
在python中可以通过in和not in关键字来判读一个list中是否包含一个元素: str = ['s','i','m','o','n'] if 'e' in str: print("e ...