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函数篇0-1

    创建类和对象 面向对象编程是一种编程方式,此编程方式的落地需要使用 “类” 和 “对象” 来实现,所以,面向对象编程其实就是对 “类” 和 “对象” 的使用. 类就是一个模板,模板里可以包含多个函数, ...

  2. Codeforces 1237B. Balanced Tunnel

    传送门 这一题有点意思 首先预处理出 $pos[x]$ 表示编号 $x$ 的车是第几个出隧道的 然后按进入隧道的顺序枚举每辆车 $x$ 考虑有哪些车比 $x$ 晚进入隧道却比 $x$ 早出隧道 显然是 ...

  3. 牛客 70E 乌龟跑步 (bitset优化dp)

    有一只乌龟,初始在0的位置向右跑. 这只乌龟会依次接到一串指令,指令T表示向后转,指令F表示向前移动一个单位.乌龟不能忽视任何指令.现在我们要修改其中正好n个指令(一个指令可以被改多次,一次修改定义为 ...

  4. Python 最常见的 170 道面试题解析:2019 最新

    Python 最常见的 170 道面试题解析:2019 最新 2019年06月03日 23:30:10 GitChat的博客 阅读数 21329 文章标签: PythonPython入门Python面 ...

  5. Java EE javax.servlet.http中的HttpRequest抽象类

    HttpRequest抽象类 public abstract class HttpServlet extends GenericServlet 实现的接口有:Serializable, Servlet ...

  6. Spring实战(六)自动装配的歧义性

    1.Spring进行自动装配时碰到的bean歧义性问题. 在进行自动装配时,只有仅有一个bean匹配所需结果时,才是可行的. 如果不仅仅一个bean能够匹配结果,例如一个接口有多个实现,这种歧义性会阻 ...

  7. Java反射理解(五)-- 方法反射的基本操作

    Java反射理解(五)-- 方法反射的基本操作 方法的反射 1. 如何获取某个方法 方法的名称和方法的参数列表才能唯一决定某个方法 2. 方法反射的操作 method.invoke(对象,参数列表) ...

  8. docker_nginx_php_mysql

    https://blog.csdn.net/miwumuge/article/details/83386679 问题 1.容器内访问宿主机地址, host.docker.internal

  9. JS基础_相等运算符

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 09 Python之IO多路复用

    四种常见IO模型 阻塞IO(blocking IO).非阻塞IO(nonblocking IO).IO多路复用(IOmultiplexing).异步IO(asynchronous IO) IO发生时涉 ...