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][ ...
随机推荐
- 无可匹敌的创建job(细化很多细节)
declare jobno binary_integer ; rm_days number := 15; --保留多少天的数据,单位天数 rm_hour ...
- ios UIWebView截获html并修改便签内容
需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容: 实例代码: 服务器端 ...
- javascript面向对象程序设计系列(一)---创建对象
javascript是一种基于对象的语言,但它没有类的概念,所以又和实际面向对象的语言有区别,面向对象是javascript中的难点之一.现在就我所理解的总结一下,便于以后复习: 一.创建对象 1.创 ...
- Glibc和GCC,ARM-LINUX-GCC的关系
看到有些贴子/blog上提到「Glibc编译器」,这是个错误的用语.Glibc不是编译器,Glibc不是编译器,Glibc不是编译器.重要的事情说三遍.GCC才是编译器.
- 实例:图形绘制[OpenCV 笔记15]
DrawShapes.cxx # include "DrawShapes_utils.h" #define WINDOW_NAME1 "Painting 1" ...
- itoa 和_itoa_s
1> itoa, 将整数转换为字符串. char * itoa ( int value, char * buffer, int radix ); 它包含三个参数: value, 是要转换的数字 ...
- JPA的泛型DAO设计及使用
使用如Hibernate或者JPA作为持久化的解决方案时,设计一个泛型的DAO抽象父类可以方便各个实体的通用CRUD操作.由于此时大部分实体DAO的CRUD操作基本一样,采用泛型设计解决这个问题,带来 ...
- python 自动化之路 day 07 面向对象基础
本节内容: 面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法. 面向对象编程 OOP编程是利用"类"和"对象" ...
- sed工具使用
sed命令使用形式 1.sed命令从管道中读取数据处理 command | sed ' edit command' 通过管道把一个命令的标准输出读入到sed的标准输入,sed就起到了过滤作用 2.se ...
- 使用win8.1 x64 office2010 php 使用 pdo_odbc 连接excel失败的问题
public function init($filePath){ $dbq = iconv('UTF-8',"GBK",BASEPATH.'../'.$filePath); $ds ...