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][ ...
随机推荐
- Servlet单实例多线程模式
http://kakajw.iteye.com/blog/920839 前言:Servlet/JSP技术和ASP.PHP等相比,由于其多线程运行而具有很高的执行效率.由于Servlet/JSP默认是以 ...
- android使用广播退出应用程序
由于在(Widget或Service.BroadcastReceiver中)使用startActivity()方法启动activity时需使用FLAG_ACTIVITY_NEW_TASK flag,所 ...
- windows2008 x86 安装 32位oracle
1.windows 2008 升级到sp2补丁 下载地址 : http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=15278 2. ...
- 关于block块使用的6点注意事项
对于刚学习OC新伙伴,block块一直都是一个比较纠结.比较难懂的知识点,不过,在使用一段时间后,就会感觉很酸爽.block块的原理及使用我就不再赘述,网上有很多这方面的资料.我个人使用这么长时间以来 ...
- 关于tableView的那些坑(一)—— automaticallyAdjustsScrollViewInsets属性
最近用tabbar来切换控制器,用childViewController来实现多控制器管理,多列表切换,在子控制器中设置了automaticallyAdjustsScrollViewInsets属性为 ...
- PHP学习笔记(八)
关于PHP中的缓存函数ob_start() and ob_end_flush(). PHP输出机制:输出内容->缓存->输出到浏览器.ob_start(callback function) ...
- nginx方面的书籍资料链接
http://tengine.taobao.org/book/ http://blog.sina.com.cn/s/articlelist_1929617884_0_1.html http://blo ...
- libz.so库分析
from:http://blog.chinaunix.net/uid-12773189-id-84605.html 1.查看库文件是由哪个软件包提供的空闲时打开/usr/lib目录(因为我知道这个目录 ...
- mac 下 sublime text 运行c++/c 不能使用scanf/cin
{ "cmd": ["g++", "${file}", "-o", "${file_path}/${file_ ...
- python 面向对象 class 老男孩选课系统
要求:1. 创建北京.上海 2 所学校 class2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. 课程包含,周期,价格,通过学校创建课 ...