hdu 5753
Permutation Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 574 Accepted Submission(s): 346
Special Judge
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).
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).
If the absolute error between your answer and the standard answer is no more than 10−4, your solution will be accepted.
3 2 4 5
5
3 5 99 32 12
52.833333
题意:给你一个有n个数的数列c1~cn,h1~hn为1~n的排列,求ci[hi>hi-1 and hi>hi+1]的期望和。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=100000+10; #define MM(a,b) memset(a,b,sizeof(a));
#define FOR(i,n) for(int i=1;i<=n;i++)
#define SC scanf
#define PF printf
#define PB push_back
#define CT continue double c[1009];
int main()
{
int n;
while(~SC("%d",&n)){
FOR(i,n) SC("%lf",&c[i]);
double ans=(c[1]+c[n])/2;
for(int i=2;i<=n-1;i++){
ans+=c[i]/3;
}
PF("%.9f\n",ans);
}
return 0;
}
总是看了题解后才觉得题目好水,,,需要改变一下比赛时的心态了,,
因为假设两端的数字为大和小两种情况,中间的数字为大中小三种情况;
002 Permutation Bo
根据期望的线性性,我们可以分开考虑每个位置对答案的贡献。
可以发现当ii不在两边的时候和两端有六种大小关系,其中有两种是对答案有贡献的。
那么对答案的贡献就是\frac{c_i}{3}3ci。
在两端的话有两种大小关系,其中有一种对答案有贡献。
那么对答案的贡献就是\frac{c_i}{2}2ci。
复杂度是O(n)O(n)。
注意特判n=1n=1的情况。
hdu 5753的更多相关文章
- 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
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 题目大意: 两个序列h和c,h为1~n的乱序.h[0]=h[n+1]=0,[A]表示A为真则为 ...
- HDU - 5753 多校联萌3-2
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5753 Sample Input Sample Output 6.000000 52.833333 分析 ...
- hdu 5753 Permutation Bo 水题
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种可能.小,中,大.其中有 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- pycharm虚拟环境的搭建
目录 优点 windows 安装 配置虚拟环境管理器工作目录 MacOS.Linux 安装 工作文件 配置 使用 pycharm使用 新建项目 添加环境 使用环境 优点 1.使不同应用开发环境相互独立 ...
- IaaS、PaaS、SaaS是云计算的三种服务模式
IaaS.PaaS.SaaS是云计算的三种服务模式 1. SaaS:Software-as-a-Service(软件即服务)提供给客户的服务是运营商运行在云计算基础设施上的应用程序,用户可以在各种设备 ...
- Function(Of T) as T 泛型类型多态返回对象的实现
Shared Function ResultT(Of T As result)(msg As String, Optional success As Boolean = False) As T Dim ...
- O036、Snapshot Instance 操作详解
参考https://www.cnblogs.com/CloudMan6/p/5510296.html 有时候系统损坏的很严重,通过 Rescue 操作无法修复,那么我们就得重新考虑通过备份恢复了. ...
- linux mint ubuntu 安装qq
git clone https://gitee.com/wszqkzqk/deepin-wine-for-ubuntu.gitcd deepin-wine-for-ubuntu./install.sh ...
- 帝国cms 通过栏目获取某个栏目的详情
当是某个栏目的时候,获取另外一个栏目下第一篇文章的详情,否则获取当前栏目下第一篇文章的详情 <?php $classid = $GLOBALS['navclassid']; if($classi ...
- react——使用this.setState({ })修改state状态值
使用this.setState({ }) 还可以修改后追加传的参数 效果如下: this.setState({ })方法是异步的
- Oracle层次查询start with connect by
博客参考:https://www.cnblogs.com/jerryxing/articles/2339352.html start with connect by 层次查询(Hierarchical ...
- 网络基础篇之NAT(原理)
一.NAT的产生 由于网络的飞速发展和网络应用的极速增多,致使IPv4可用地址空间逐渐枯竭.尽管IPv6可以在根本上解决地址枯竭问题,但IPv4发展到IPv6还需要一个过渡,而这便产生了NAT. 二. ...
- 最贵的AMD 7nm显卡来了!这设计 够狂野
ROG STRIX系列配备三个风扇(支持智能启停).多条热管.金属背板,厚度达2.5个插槽位,另有两个8针辅助供电,因此最大供电能力375W,必然会预先大幅超频,而且应该仍有手动超频空间,当然也少不了 ...