HDU-6070 Dirt Ratio
来源:互联网 发布:淘宝账号为什么会被盗 编辑:程序博客网 时间:2024/06/06 21:41
Dirt Ratio
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1117 Accepted Submission(s): 493
Special Judge
Problem Description
In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the following way. First let's ignore all the problems the team didn't pass, assume the team passed X problems during the contest, and submitted Y times for these problems, then the ''Dirt Ratio'' is measured as XY . If the ''Dirt Ratio'' of a team is too low, the team tends to cause more penalty, which is not a good performance.
Picture from MyICPC
Little Q is a coach, he is now staring at the submission list of a team. You can assume all the problems occurred in the list was solved by the team during the contest. Little Q calculated the team's low ''Dirt Ratio'', felt very angry. He wants to have a talk with them. To make the problem more serious, he wants to choose a continuous subsequence of the list, and then calculate the ''Dirt Ratio'' just based on that subsequence.
Please write a program to find such subsequence having the lowest ''Dirt Ratio''.
Picture from MyICPC
Little Q is a coach, he is now staring at the submission list of a team. You can assume all the problems occurred in the list was solved by the team during the contest. Little Q calculated the team's low ''Dirt Ratio'', felt very angry. He wants to have a talk with them. To make the problem more serious, he wants to choose a continuous subsequence of the list, and then calculate the ''Dirt Ratio'' just based on that subsequence.
Please write a program to find such subsequence having the lowest ''Dirt Ratio''.
Input
The first line of the input contains an integer T(1≤T≤15) , denoting the number of test cases.
In each test case, there is an integern(1≤n≤60000) in the first line, denoting the length of the submission list.
In the next line, there aren positive integers a1,a2,...,an(1≤ai≤n) , denoting the problem ID of each submission.
In each test case, there is an integer
In the next line, there are
Output
For each test case, print a single line containing a floating number, denoting the lowest ''Dirt Ratio''. The answer must be printed with an absolute error not greater than 10−4 .
Sample Input
151 2 1 2 3
Sample Output
0.5000000000HintFor every problem, you can assume its final submission is accepted.
Source
2017 Multi-University Training Contest - Team 4
题意:
简单理解就是 在连续子区间内
比值 = 元素种类个数 / 连续子区间长度
求比值的最小值
题解:
1,首先二分答案,来逼近答案;
2,列出求解式子:
size(l,r)/(r-l+1)<=mid
size(l,r)为区间(l,r)中不同的元素个数;
mid是二分的结果(即比值);
接下来式子可以转化为:size(l,r)+mid*l<=(r+1)*mid;
然后,枚举区间右端点从1到n
从线段树中去维护size(l,r)+mid*l的最小值;
#include<stdio.h>#include<string.h>#include<algorithm>#define ll long longusing namespace std;const int MAX = 1e5 + 5;const ll INF = 1e10;int last[MAX],pre[MAX],n;double add[MAX*4],sum[MAX*4];void UP(int rt){sum[rt] = min(sum[rt*2],sum[rt*2+1]);}void Down(int rt){add[rt*2] += add[rt];add[rt*2+1] += add[rt];sum[rt*2] += add[rt];sum[rt*2+1] += add[rt];add[rt] = 0;}void build(int l,int r,int rt){sum[rt] = add[rt] = 0;if(l == r)return ;int m = (l + r) >> 1;build(l,m,rt*2);build(m+1,r,rt*2+1);UP(rt);}void update(int L,int R,double c,int l,int r,int rt){if(L <= l && R >= r){add[rt] += c;sum[rt] += c;return ;}Down(rt);int m = (l + r) >> 1;if(L <= m)update(L,R,c,l,m,rt*2);if(R > m)update(L,R,c,m+1,r,rt*2+1);UP(rt);}double query(int L,int R,int l,int r,int rt){if(L <= l && R >= r)return sum[rt];Down(rt);int m = (l + r) >> 1;double ans = n;if(L <= m)ans = min(ans,query(L,R,l,m,rt*2));if(R > m)ans = min(ans,query(L,R,m+1,r,rt*2+1));UP(rt);return ans;}bool solve(double k){build(1,n,1);for(int i = 1;i <= n;i++){update(pre[i] + 1,i,1,1,n,1);update(1,i,-k,1,n,1);if(query(1,i,1,n,1) <= 0)return 1;}return 0;}int main(){int T,x;scanf("%d",&T);while(T--){scanf("%d",&n);memset(last,0,sizeof(last));memset(pre,0,sizeof(pre));for(int i = 1;i <= n;i++){scanf("%d",&x);pre[i] = last[x];last[x] = i;}double l = 0,r = 1;for(int i = 0;i < 20;i++){double m = (l + r) / 2;if(solve(m))r = m;elsel = m;}printf("%.9lf\n",r);}return 0;}
阅读全文
2 0
- hdu 6070 Dirt Ratio
- HDU 6070 Dirt Ratio
- HDU-6070 Dirt Ratio
- HDU 6070 Dirt Ratio
- HDU 6070 Dirt Ratio
- hdu 6070 Dirt Ratio
- HDU 6070 Dirt Ratio
- hdu 6070 Dirt Ratio
- HDU 6070 Dirt Ratio
- HDU 6070 Dirt Ratio 线段树 二分
- HDU 6070 Dirt Ratio [二分+线段树]
- hdu 6070 Dirt Ratio 二分,线段树
- hdu 6070 Dirt Ratio(线段树+二分)
- hdu 6070 Dirt Ratio二分 线段树
- HDU 6070 Dirt Ratio 线段树 + 二分
- 【HDU 6070 Dirt Ratio】 二分 & 线段树
- HDU 6070 Dirt Ratio 二分+线段树
- HDU 6070 Dirt Ratio 线段树
- 一个生成验证字符或数字的增强类(基于.net1.1)及调用示例
- Python学习第一记——猜数游戏
- 欧拉函数的求法(线性筛)
- linux下openvpn服务器搭建
- docker remote api 调用
- HDU-6070 Dirt Ratio
- uvalive 4329 Ping Pong(树状数组)
- Uboot到底如何启动内核
- 距离变换distanceTransform应用——寻找图像的质心
- Python-numpy
- Easyui-combobox使用
- MySql操作
- 数据库设计
- 清晰明了告诉你RequireJS 的使用。