ZOJ-2091-Mean of Subsequence
2009-05-30 00:53
190 查看
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.
Sample Input
10
2 10 4 6 5 10 10 2 3 2
Sample Output
5.777778
其实就是找后k个数的平均值的最大值 k=1,2,3……n ,记做kmax
因为一旦Roy选了这个kmax,PMH必定会将所选数字长度最大化
用反证法证明:如果所选长度的最后一个数字不是n 而是kmax与n中间的某个数t
那么也就是说ave(kmax...t)<ave(kmax...n)
那么必有 ave(t+1...n)>ave(kmax...n) 说明最后t+1个数的平均数最大 与题设矛盾
#include <stdio.h>
#define MAXNUM 10000
int main()
{
{
{
{
sum-=num[i];
ave=sum*1.0/t--;
if (ave>max)
max=ave;
}
printf("%.6f\n",max);
}
return 0;
}
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
10
2 10 4 6 5 10 10 2 3 2
Sample Output
5.777778
其实就是找后k个数的平均值的最大值 k=1,2,3……n ,记做kmax
因为一旦Roy选了这个kmax,PMH必定会将所选数字长度最大化
用反证法证明:如果所选长度的最后一个数字不是n 而是kmax与n中间的某个数t
那么也就是说ave(kmax...t)<ave(kmax...n)
那么必有 ave(t+1...n)>ave(kmax...n) 说明最后t+1个数的平均数最大 与题设矛盾
#include <stdio.h>
#define MAXNUM 10000
int main()
{
{
{
{
sum-=num[i];
ave=sum*1.0/t--;
if (ave>max)
max=ave;
}
printf("%.6f\n",max);
}
return 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 3885 The Exchange of Items
- HDU1423&ZOJ2432 - Greatest Common Increasing Subsequence(LCIS最长公共上升子序列模板)
- ZOJ Problem Set - 2975 Kinds of Fuwas
- zoj 1460 The Partition of a Cake
- Sum of Factorials zoj
- zoj 1232 Adventure of Super Mario
- ZOJ 3123 Subsequence (动态规划)
- A - Ace of Aces——ZOJ
- ZOJ 1763 A Simple Question of Chemistry
- ZOJ Problem Set - 1090 The Circumference of the Circle
- zoj 3201 简单树形dp Tree of Tree
- ZOJ 1827 The Game of 31
- zoj 2830 Champion of the Swordsmanship
- zoj2818 Root of the Problem 简单数学 开方
- zoj 2486 Power of Cryptography