题目链接:

Permutation Bo

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 131072/131072 K (Java/Others)

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
 
题意:
 
求这个函数值得期望;
 
思路:
 
发现首尾的概率为1/2,中间的为1/3;求一下就好;
 
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef unsigned long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e7+10;
const int maxn=1000+10;
const double eps=1e-8; int c[1100]; int main()
{
int n;
while(cin>>n)
{
For(i,1,n)
{
read(c[i]);
}
double ans=0;
for(int i=2;i<n;i++)
{
ans=ans+c[i]*1.0/3;
}
ans=ans+(c[1]+c[n])*1.0/2;
printf("%.6lf\n",ans);
} return 0;
}

  

hdu-5753 Permutation Bo(概率期望)的更多相关文章

  1. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  2. hdu 5753 Permutation Bo 水题

    Permutation Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  3. hdu 5753 Permutation Bo

    这里是一个比较简单的问题:考虑每个数对和的贡献.先考虑数列两端的值,两端的摆放的值总计有2种,比如左端:0,大,小:0,小,大:有1/2的贡献度.右端同理. 中间的书总计有6种可能.小,中,大.其中有 ...

  4. 【数学】HDU 5753 Permutation Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 题目大意: 两个序列h和c,h为1~n的乱序.h[0]=h[n+1]=0,[A]表示A为真则为 ...

  5. 2019杭电多校第七场 HDU - 6656 Kejin Player——概率&&期望

    题意 总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层.接下来有 $q$ 次询问,每次询问 $ ...

  6. hdu 5036 Explosion(概率期望+bitset)

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...

  7. HDU 4576 Robot (概率 & 期望)

    Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  8. hdu 5753

    Permutation Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  9. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

随机推荐

  1. 转载cookie理解

    本文转自https://www.cnblogs.com/dojo-lzz/p/5580301.html 服务器端像客户端发送Cookie是通过HTTP响应报文实现的,在Set-Cookie中设置需要像 ...

  2. 简单配置PonyDebugger

    OS的Debug 系统在github上还是有不少. PonyDebugger是看上去比较牛气的一个.尝试一下 Logo PonyDebugger 可以监控网络 NetworkTrafficDebugg ...

  3. java单测时的等待模块awaitility

    单测时,可以用来等待异步任务完成 在编写自动化测试用例过程中,往往会遇见被测代码有异步或者队列处理的中间过程:如果需要校验这部分结果,必须等待异步操作结束或队列消费完,而这个中间等待的时间是不确定的, ...

  4. Kaggle的Outbrain点击预测比赛分析

    https://yq.aliyun.com/articles/293596 https://www.kaggle.com/c/outbrain-click-prediction https://www ...

  5. 转:Android IOS WebRTC 音视频开发总结 (系列文章集合)

    随笔分类 - webrtc   Android IOS WebRTC 音视频开发总结(七八)-- 为什么WebRTC端到端监控很关键? 摘要: 本文主要介绍WebRTC端到端监控(我们翻译和整理的,译 ...

  6. 解决Sophos UTM 9防火墙上的“根分区填满”问题

    Resolving 'Root Partition Is Filling Up' Issue on Sophos UTM Firewall 收到“Sophos UTM 9”防火墻的“根分區填满”问题的 ...

  7. angular - 编辑html文件-4

    启动服务器: angular默认端口:4200 ng serve --port 3000 --open 输入本条命令后,会自动打开默认浏览器以及打开APP页 推荐开发工具webStorm,全平台兼容M ...

  8. ubuntu将快捷方式复制到桌面

    /usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制-桌面 就Ok

  9. caffe配置Makefile.config----ubuntu16.04--重点是matlab的编译

    来源: http://blog.csdn.net/daaikuaichuan/article/details/61414219 配置Makefile.config(参考:http://blog.csd ...

  10. 李洪强iOS开发之 - 项目架构

    李洪强iOS开发之 - 项目架构 01 - 在Appdelegate中设置跟控制器 //导入头文件