ZOJ 2091 Mean of Subsequence(博弈,反证法,结论巧妙)
来源:互联网 发布:web3.0与云计算 编辑:程序博客网 时间:2024/05/21 18:43
Given N numbers in a line, we can determine a continuous subsequence by giving its start position and its length.
PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.
You are to calculate the best result Roy can get, assuming PMH is very clever.
Input
There are multiple testcases.
Each testcase begins with a line containing N only.
The following line contains N numbers, separated by spaces.
Output
For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.
2 10 4 6 5 10 10 2 3 2
PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.
You are to calculate the best result Roy can get, assuming PMH is very clever.
Input
There are multiple testcases.
Each testcase begins with a line containing N only.
The following line contains N numbers, separated by spaces.
Output
For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.
Sample Input
102 10 4 6 5 10 10 2 3 2
Sample Output
5.777778题意:其实就是找后几个数的平均值的最大值!! (贪心策略!要找对)
一旦Roy选了这个maxk , PMH必定会将所选数字长度最大化
为什么呢??
用反证法证明:如果所选长度的最后一个数字不是最后一个数n, 而是maxk与n中间的某个数t
那么也就是说ave(maxk...t)<ave(maxk...n)
那么必有 ave(t+1...n)>ave(maxk...n) 说明t+1后面几个数的平均数最大 与题设矛盾(转载)
#include<iostream> #include<algorithm> #include<string> #include<set> #include<vector>#include<cmath>#include<queue>#include<string.h> #include<stdlib.h> #include<stdio.h>#define ll long long #define eps 10e-7using namespace std;double x[100001];int main(){int n;while(cin>>n){x[0]=0;for(int i=1;i<=n;++i){cin>>x[i];x[i]+=x[i-1];}double s=-100000000; //注意这里不能设成0 for(int i=1;i<=n;++i){double p=(double)(x[n]-x[i-1])/(n-i+1);if(p>s)s=p;}printf("%.6lf\n",s);}return 0;}
0 0
- ZOJ 2091 Mean of Subsequence(博弈,反证法,结论巧妙)
- ZOJ-2091-Mean of Subsequence (反证法的运用!!)
- ZOJ-2091-Mean of Subsequence (反证法的运用!!)
- ZOJ 2091 Mean of Subsequence
- ZOJ-2091 Mean of Subsequence
- zoj 2091 Mean of Subsequence(奇怪的贪心)
- 51nod1070(博弈,有趣的结论)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- 利用反证法证明Nim Game中的定理(结论)
- ZOJ 2686(规律博弈)
- 这么巧妙思路(二)Longest Ordered Subsequence
- ZOj 3964Yet Another Game of Stones(nim博弈)
- 博弈小结(POJ ,HDU,ZOJ博弈问题小结)
- ZOJ 3666 Alice and Bob(博弈)
- zoj 3513 Human or Pig(博弈)
- 博弈--ZOJ 3084 S-Nim(SG)
- zoj 3882 Help Bob(博弈)
- 回溯法
- 面向对象中比较重要的this,static,super,单利设计的总结和归纳
- Android的三种网络通信方式
- 地宫取宝
- 欢迎使用CSDN-markdown编辑器
- ZOJ 2091 Mean of Subsequence(博弈,反证法,结论巧妙)
- 本科生以及研究生信息
- ubuntu 安装 wps
- 欢迎使用CSDN-markdown编辑器
- Python核心编程第七章笔记及习题记录
- android SDK相关下载
- PHP 测试变量状态
- 清除APK缓存和获取APK的数据大小
- js中document.write用法