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

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
 
Source
 

题意:给你一个有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}​3​​c​i​​​​。

在两端的话有两种大小关系,其中有一种对答案有贡献。

那么对答案的贡献就是\frac{c_i}{2}​2​​c​i​​​​。

复杂度是O(n)O(n)。

注意特判n=1n=1的情况。

hdu 5753的更多相关文章

  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

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

  3. HDU - 5753 多校联萌3-2

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5753 Sample Input Sample Output 6.000000 52.833333 分析 ...

  4. hdu 5753 Permutation Bo 水题

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

  5. hdu 5753 Permutation Bo

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

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Python库的优雅安装及PyCharm虚拟环境配置

    一.安装python库 安装python库有几种方式: 1. 使用pip命令行,如:pip install Pillow 2. 在pycharm中安装 3. 使用Anaconda批量安装常用模块 在使 ...

  2. pg_ctl — 启动、停止、重启 PostgreSQL

    pg_ctl 名称 pg_ctl -- 启动.停止.重启 PostgreSQL 语法 pg_ctl start [-w] [-s] [-D datadir] [-l filename] [-o opt ...

  3. javascript——创建对象的方式

    对象:在JavaScript中,对象是拥有属性和方法的数据. JavaScript自定义对象方式有以下7种:直接创建方式.对象初始化器方式.构造函数方法.prototype原型方式.混合的构造函数/原 ...

  4. 解决maven依赖包下载慢的问题

    修改maven 目录下setting.xml配置文件 在mirrors中添加如下配置即可 <mirror> <id>alimaven</id> <name&g ...

  5. QT 安卓 悬浮窗权限动态申请

    一:申请方式: String ACTION_MANAGE_OVERLAY_PERMISSION = "android.settings.action.MANAGE_OVERLAY_PERMI ...

  6. C#异步编程学习笔记之-async和await(续)

    书接上文,本篇主要记录的内容要点:1.针对async和await在实际应用中的使用方式:2.异步方法返回值(有返回值和无返回值)的两种情况: 示例一(无返回值): using System; usin ...

  7. C++虚函数和纯虚函数的用法和区别

    C++虚函数与纯虚函数用法与区别(转)   1. 虚函数和纯虚函数可以定义在同一个类(class)中,含有纯虚函数的类被称为抽象类(abstract class),而只含有虚函数的类(class)不能 ...

  8. Delphi WaitCommEvent函数

  9. casperjs 源码

    1.首当其冲github 地址: https://github.com/casperjs

  10. python常用模块:re模块案例、subprocess

    今日内容: 一.re模块二.re练习三.subproces模块 一.re模块 import re # [] 范围匹配 中间 用-来连接 # re.findall("[a-zA-Z0-9]&q ...