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, ...
随机推荐
- Java获取时间,将当前时间减一年,减一天,减一个月
在Java中操作时间的时候,需要计算某段时间开始到结束的区间日期,常用的时间工具 Date date = new Date();//获取当前时间 Calendar calendar = Calenda ...
- go语言学习之路(一)Hello World
为什么要使用 Go 语言?Go 语言的优势在哪里? 1.部署简单. 2.并发性好. 3.良好的语言设计. 4.执行性能好. Go环境搭建 Golang下载 国外镜像 https://www.gola ...
- javascript完美拖拽的实现
直接上代码: HTML代码: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta chars ...
- 20155338 2016-2017-2 《Java程序设计》第6周学习总结
20155338 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 输入和输出 • 串流设计概念 要想活用输入/输出API,一定先要了解Java中如何以串流抽象 ...
- Zookeeper笔记之quota
一.节点配额概述 zookeeper中可以往节点存放数据,但是一般来说存放数据总是要有个度量的对吧,不然空间就那么大,如果某个节点将空间全占用了其它节点没得用了,所以zookeeper提供了一个对节点 ...
- Spring Boot 多模块项目创建与配置 (一)
最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都使用spring boot框架.之前有零零散散学过一些 ...
- python selenium - web自动化环境搭建
前提: 安装python环境. 参考另一篇博文:https://www.cnblogs.com/Simple-Small/p/9179061.html web自动化:实现代码驱动浏览器进行点点点的操作 ...
- 【ARTS】01_06_左耳听风-20181217~1223
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- mac ssh 自动登陆设置
1.首先找到.ssh目录 一般在用户名目录下. ls -a查看 如果没有就重新创建一个 chennan@bogon :mkdir .ssh chennan@bogon 查看当前的 bogon:.ssh ...
- Android 6.0 变更
Android 6.0(API 级别 23)除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 如果您之前发布过 Andr ...