Dirt Ratio

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1473    Accepted Submission(s): 683
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 Xproblems 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 MyICPCLittle 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 integer n(1≤n≤60000) in the first line, denoting the length of the submission list.
In the next line, there are n positive integers a1,a2,...,an(1≤ai≤n), denoting the problem ID of each submission.
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
1
5
1 2 1 2 3
Sample Output
0.5000000000

Hint

For every problem, you can assume its final submission is accepted.

【题意】给你一个序列,问你对于任意 子序列,序列中数的种数/区间长度最小是多少。
【分析】二分答案midmid,检验是否存在一个区间满足cnt(l,r)/(r-l+1)≤mid,
 也就是cnt(l,r)+mid*l<=mid*(r+1)。从左往右枚举每个位置作为r,
 当r变化为r+1时,对cnt的影响是一段区间加1,线段树维护区间最小值即可。线段树维护的是当枚举到r时,每个区间内cnt(l,r)+mid*l的最小值,
 跟mid*(r+1)比较大小即可。这个题跟Codeforces Round #426 (Div. 2) D The Bakery很像,代码几乎一样,思想相同。
http://www.cnblogs.com/jianrenfang/p/7265602.html
  1. #include <bits/stdc++.h>
  2. #define inf 0x3f3f3f3f
  3. #define met(a,b) memset(a,b,sizeof a)
  4. #define pb push_back
  5. #define mp make_pair
  6. #define inf 0x3f3f3f3f
  7. using namespace std;
  8. typedef long long ll;
  9. const int N = 6e4+;;
  10. const int M = ;
  11. const int mod = 1e9+;
  12. const double pi= acos(-1.0);
  13. typedef pair<int,int>pii;
  14. int n,k,ans;
  15. int a[N],lazy[N*];
  16. int pre[N],pos[N];
  17. double dp[N];
  18. double mx[N*];
  19. void pushUp(int rt){
  20. mx[rt]=min(mx[rt<<],mx[rt<<|]);
  21. }
  22. void pushDown(int rt){
  23. if(lazy[rt]){
  24. lazy[rt<<]+=lazy[rt];
  25. lazy[rt<<|]+=lazy[rt];
  26. mx[rt<<]+=lazy[rt];
  27. mx[rt<<|]+=lazy[rt];
  28. lazy[rt]=;
  29. }
  30. }
  31. void build(int l,int r,int rt,double x){
  32. lazy[rt]=;
  33. if(l==r){
  34. mx[rt]=x*l;
  35. return;
  36. }
  37. int mid=(l+r)>>;
  38. build(l,mid,rt<<,x);
  39. build(mid+,r,rt<<|,x);
  40. pushUp(rt);
  41. }
  42. void upd(int L,int R,int l,int r,int x,int rt){
  43. if(L<=l&&r<=R){
  44. mx[rt]+=x;
  45. lazy[rt]+=x;
  46. return;
  47. }
  48. pushDown(rt);
  49. int mid=(l+r)>>;
  50. if(L<=mid)upd(L,R,l,mid,x,rt<<);
  51. if(R>mid) upd(L,R,mid+,r,x,rt<<|);
  52. pushUp(rt);
  53. }
  54. double qry(int L,int R,int l,int r,int rt){
  55. if(L<=l&&r<=R){
  56. return mx[rt];
  57. }
  58. pushDown(rt);
  59. double ret=;
  60. int mid=(l+r)>>;
  61. if(L<=mid)ret=min(ret,qry(L,R,l,mid,rt<<));
  62. if(R>mid)ret=min(ret,qry(L,R,mid+,r,rt<<|));
  63. return ret;
  64. }
  65. int main(){
  66. int T;
  67. scanf("%d",&T);
  68. while(T--){
  69. met(pos,);
  70. scanf("%d",&n);
  71. for(int i=;i<=n;i++){
  72. scanf("%d",&a[i]);
  73. pre[i]=pos[a[i]];
  74. pos[a[i]]=i;
  75. }
  76. double l=,r=;
  77. for(int i=;i<=;i++){
  78. double mid = (l+r)/;
  79. build(,n,,mid);
  80. bool ok=true;
  81. for(int j=;j<=n;j++){
  82. upd(pre[j]+,j,,n,,);
  83. dp[j]=qry(,j,,n,);
  84. if(dp[j]<=mid*(j+)){
  85. ok=false;break;
  86. }
  87. }
  88. if(!ok)r=mid;
  89. else l=mid;
  90. }
  91. printf("%.9f\n",(l+r)/);
  92. }
  93. }

HDU 6070 Dirt Ratio(线段树)的更多相关文章

  1. hdu 6070 Dirt Ratio 线段树+二分

    Dirt Ratio Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Spe ...

  2. HDU 6070 - Dirt Ratio | 2017 Multi-University Training Contest 4

    比赛时会错题意+不知道怎么线段树维护分数- - 思路来自题解 /* HDU 6070 - Dirt Ratio [ 二分,线段树 ] | 2017 Multi-University Training ...

  3. HDU 6070 Dirt Ratio(分数规划+线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 找出一个区间,使得(区间内不同数的个数/区间长度)的值最小,并输出该值. 思路: 因为是要求$\f ...

  4. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  5. hdu 6070 Dirt Ratio

    题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6070 (2017 Multi-University Training Contest - Team ...

  6. HDU 6070题解(二分+线段树)

    题面 传送门 此题的题意不是很清晰,要注意的一点是在区间[L,R]中,默认题目编号最后一次出现的时候是AC的 比如1 2 1 2 3 ,在区间[1,4]中,第3次提交时AC第1题,第4次提交时AC第2 ...

  7. hdu 5700区间交(线段树)

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  8. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  9. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

随机推荐

  1. mysql创建用户,并授权

    1.创建用户 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; host分下列3种情况:'%' - 所有情况都能访问‘localhost’ ...

  2. Strand Sort

    Strand sort是思路是这样的,它首先需要一个空的数组用来存放最终的输出结果,给它取个名字叫"有序数组" 然后每次遍历待排数组,得到一个"子有序数组",然 ...

  3. 「6月雅礼集训 2017 Day7」电报

    [题目大意] 有n个岛屿,第i个岛屿有有向发射站到第$p_i$个岛屿,改变到任意其他岛屿需要花费$c_i$的代价,求使得所有岛屿直接或间接联通的最小代价. $1 \leq n \leq 10^5, 1 ...

  4. 【BZOJ】1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    [算法]模拟 #include<cstdio> #include<algorithm> using namespace std; ,maxm=; int a[maxn],A[m ...

  5. quick-cocos2dx 悬浮节点(NotificationNode)

    cocos2dx 开发游戏时,有时某些节点不需要随着场景的切换而销毁.但cocos2dx的机制只允许同时只有一个运行的场景,如果你的所有节点都是依附于这个场景的,那场景的切换必然带来节点的销毁. 比如 ...

  6. python学习笔记(一)之为什么学习python

    python的特点: 跨平台 实现同一个功能是Java代码的1/5 python应用范围: 操作系统 web 3D动画 企业应用 云计算 如何学习python? 学习语法 验证例子 学会总结 课外实践

  7. Spring总结以及在面试中的一些问题(山东数漫江湖)

    1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...

  8. 【洛谷 P3899】 [湖南集训]谈笑风生 (主席树)

    题目链接 容易发现\(a,b,c\)肯定是在一条直链上的. 定义\(size(u)\)表示以\(u\)为根的子树大小(不包括\(u\)) 分两种情况, 1.\(b\)是\(a\)的祖先,对答案的贡献是 ...

  9. Python模块学习 - Argparse

    argparse模块 在Python中,argparse模块是标准库中用来解析命令行参数的模块,用来替代已经过时的optparse模块.argparse模块能够根据程序中的定义从sys.argv中解析 ...

  10. 【LabVIEW技巧】策略模式

    前言 在之前的文章提到了如何学习OOP以及对应的简单工厂模式,由于时间比较长,我们先回顾一下原有内容,然后继续了解新的模式. 为什么学习OOP 在测控系统的软件开发过程中,LabVIEW工程师一直认为 ...