hdu 5753 Permutation Bo 水题
Permutation Bo
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5753
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
Hint
题意
给你c数组,如果h[i]>h[i-1]和h[i]>h[i+1],答案就加上c。
h是1-n的排列,h[0]=0,h[n+1]=0
然后求最后答案的期望是多少
题解:
根据期望的线性性,我们可以分开考虑每个位置对答案的贡献。
可以发现当ii不在两边的时候和两端有六种大小关系,其中有两种是对答案有贡献的。
那么对答案的贡献就是\(\frac{c_i}{3}\)
在两端的话有两种大小关系,其中有一种对答案有贡献。
那么对答案的贡献就是\(\frac{c_i}{2}\)
复杂度是O(n)。
注意特判n=1的情况。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n;
int c[maxn];
void solve(){
for(int i=1;i<=n;i++)
scanf("%d",&c[i]);
if(n==1){
double ans = c[1];
printf("%.12f\n",ans);
return;
}
if(n==2){
double ans = (c[1]+c[2])/2.0;
printf("%.12f\n",ans);
return;
}
double ans = 0;
for(int i=2;i<n;i++)
ans += (c[i])/3.0;
ans+=c[1]/2.0;
ans+=c[n]/2.0;
printf("%.12f\n",ans);
}
int main(){
while(scanf("%d",&n)!=EOF)solve();
return 0;
}
hdu 5753 Permutation Bo 水题的更多相关文章
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- hdu 5753 Permutation Bo
这里是一个比较简单的问题:考虑每个数对和的贡献.先考虑数列两端的值,两端的摆放的值总计有2种,比如左端:0,大,小:0,小,大:有1/2的贡献度.右端同理. 中间的书总计有6种可能.小,中,大.其中有 ...
- 【数学】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为真则为 ...
- hdu 5752 Sqrt Bo 水题
Sqrt Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f ...
- hdu 1106:排序(水题,字符串处理 + 排序)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 4950 Monster (水题)
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...
- HDU 4813 Hard Code 水题
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDOJ/HDU 2560 Buildings(嗯~水题)
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...
随机推荐
- [iOS]图片高清度太高, 导致内存过大Crash
先说一下状况, 后台提供的图片太高清了, 每个图片都在2-4MB, iOS上每个页面需要同时下载并展示10-15张. 这个时候, 如果我多滑动collectionView几次, 直接App就崩溃了(r ...
- ODPS_ele—UDF Python API
自定义函数(UDF) UDF全称User Defined Function,即用户自定义函数.ODPS提供了很多内建函数来满足用户的计算需求,同时用户还可以通过创建自定义函数来满足不同的计算需求.UD ...
- Zookeeper笔记之四字命令
Zookeeper支持一些命令用来获取服务的状态和相关信息,因为这些命令都是四个字母的,所以一般称为四字命令. 四字命令可以使用telnet或者nc向服务器提交,使用下面这个脚本可以当做是一个简易的客 ...
- SQL Server 索引(一)数据结构和存储结构
本文关注以下方面(本文所有的讨论基于SQL Server数据库): 索引的分类: 索引的结构: 索引的存储 一.索引定义分类 让我们先来回答几个问题: 什么是索引? 索引是对数据库表中一列或多列的值进 ...
- dblinks
一.Oracle数据库链Database links的作用 当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本 ...
- 002_docker构建zookeeper环境
最近因为要维护公司zk环境,所以自己先得搞一套先玩玩 git地址=>https://github.com/jplock/docker-zookeeper/tree/v3.4.9 一.build ...
- 发布构件到Maven中央仓库
一.注册jira账号 访问如下网址: https://issues.sonatype.org/secure/Signup.jspa 记住邮箱,用户名,密码以备以后使用,一定牢记. 二.创建一个issu ...
- KnockoutJs学习笔记(七)
if binding与visible binding类似.不同之处在于,包含visible binding的元素会在DOM中一直保存,并且该元素相应的data-bind属性会一直保持,visible ...
- 使用VSCode创建.NET Core 项目,添加类库间引用
注:网络上搜索到的关于VsCode创建调试.Net Core 项目的文章都比较老旧,不能完全参考使用,根据网络文章.微软官方文档的指导下,学习并整理此文档,但也大体和文档学习路线相似,主要为记录学习过 ...
- K8S Dashborad登陆认证文档
K8S Dashboard是官方的一个基于WEB的用户界面,专门用来管理K8S集群,并可展示集群的状态.因为我们使用kubeadm搭建的集群会默认开启RABC(角色访问控制机制),所以我们必须要进行额 ...