2016 Multi-University Training Contest 3 hdu 5753 Permutation Bo【打表+递推】
2016-07-26 18:34
507 查看
Permutation Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
Problem Description
There are two sequences h1∼hn and c1∼cn. h1∼hn is a permutation of 1∼n. particularly, h0=hn+1=0.
We define the expression [condition] is 1 when condition is True,is 0 when condition is False.
Define the function f(h)=∑ni=1ci[hi>hi−1 and hi>hi+1]
Bo have gotten the value of c1∼cn, and he wants to know the expected value of f(h).
Input
This problem has multi test cases(no more than 12).
For each test case, the first line contains a non-negative integer n(1≤n≤1000), second line contains n non-negative integer ci(0≤ci≤1000).
Output
For each test cases print a decimal - the expectation of f(h).
If the absolute error between your answer and the standard answer is no more than 10−4, your solution will be accepted.
Sample Input
4
3 2 4 5
5
3 5 99 32 12
Sample Output
6.000000
52.833333
题目大意:给你长度为n的ci序列,已知hi是一个全排列,求期望。
思路:
1、首先没有思路的时候,暴力打表,判断每一位上的ci都使用过多少次(累加过多少次)。
发现4的时候是:12 8 8 12
发现5的时候是:60 40 40 40 60
发现6的时候是:360 240 240 240 240 360.
2、这个时候突然开始发愁,我如果每个数字都乘上一个这么大的数,必然会有爆Long Long的存在啊,不必担心,因为期望的分母是情况数,也就是n的阶乘,直接令每一位使用次数除以n的阶乘之后再乘以Ci就好啦!
3、然后我们又发现:
12/24=1/2,8/24=1/3
60/120=1/2,40/120=1/3
360/720=1/2,240/720=1/3
4、那么整理其规律,ans=if(i==0||i==n-1)ans+1/2*ci,else ans+=1/2*ci【0<=i<n】
Ac代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
double ans=0;
for(int i=0;i<n;i++)
{
int tmp;
scanf("%d",&tmp);
if(n==1)
{
ans+=tmp;
continue;
}
if(i==0||i==n-1)ans+=tmp*1.0/2*1.0;
else ans+=tmp*1.0/3*1.0;
}
printf("%.6lf\n",ans);
}
}
相关文章推荐
- MAT分析器中的shallow and retained heap详解
- 2016 Multi-University Training Contest 3 hdu 5752 Sqrt Bo【思维】
- SORT
- 我与IDEA的不舍情缘
- 2016 Multi-University Training Contest 3-1011.Teacher Bo,暴力!
- Communications link failure的解决办法
- Dialog CTS fail-DialogTest.testSetDismissMessage fail原因和解决办法
- hdu 5752 Sqrt Bo(2016 Multi-University Training Contest 3——水题)
- OnPaint和OnDraw的区别
- 11gR2 Grid infrastructure fails to install
- grails与ajax书写
- zhishangbuzaixianxilie
- 有限状态机&Time_wait的解读
- Incorrect key file for table './xx_db/xx_table.MYI'; try to repair it
- perl:warning:Setting locale failed解决办法
- HDU-2016 Multi-University Training Contest 3-Sqrt Bo-大数开方
- rails production secret_key的设置
- failed to load session "ubuntu"
- Rails Respond Format 应用
- rails中创建rake任务