地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6070

题面:

Dirt Ratio

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1599    Accepted Submission(s): 740
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 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 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.

 
思路:
  分数规划的思想:二分答案,然后check。
  check:dif(l,r)/(r-l+1)<=mid (dif(l,r)区间[l,r]的不同数个数)
  这个形式很难在短时间内check,所以考虑等式变形。
  变形成==》dif(l,r)+l*mid<=(r+1)*mid
  在这种形式下可以通过枚举r,然后线段数维护左边的值。对于新加入的一个数,会在区间[pre[x],x]内贡献1,所以进行区间更新即可。
  具体见代码:
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=6e4+;
const int mod=1e9+; int n,a[K],pre[K],b[K];
double v[*K],lz[*K];
void push_down(int o)
{
v[o<<]+=lz[o],v[o<<|]+=lz[o];
lz[o<<]+=lz[o],lz[o<<|]+=lz[o];
lz[o]=;
}
double update(int o,int l,int r,int pos,double x)
{
if(l==r) return v[o]=x;
int mid=l+r>>;
push_down(o);
if(pos<=mid) update(o<<,l,mid,pos,x);
else update(o<<|,mid+,r,pos,x);
v[o]=min(v[o<<],v[o<<|]);
}
double update2(int o,int l,int r,int nl,int nr,double x)
{
if(l==nl && r==nr) return v[o]+=x,lz[o]+=x;
int mid=l+r>>;
push_down(o);
if(nr<=mid) update2(o<<,l,mid,nl,nr,x);
else if(nl>mid) update2(o<<|,mid+,r,nl,nr,x);
else update2(o<<,l,mid,nl,mid,x),update2(o<<|,mid+,r,mid+,nr,x);
v[o]=min(v[o<<],v[o<<|]);
}
bool check(double mid)
{
for(int i=,mx=n*;i<=mx;i++) v[i]=1e9,lz[i]=;
for(int i=;i<=n;i++)
{
update(,,n,i,i*mid);
update2(,,n,pre[i]+,i,1.0);
if(v[]<(i+)*mid+eps) return ;
}
return ;
}
int main(void)
{
int t;cin>>t;
while(t--)
{
scanf("%d",&n);
memset(b,,sizeof b);
for(int i=;i<=n;i++) scanf("%d",a+i),pre[i]=b[a[i]],b[a[i]]=i;
double l=,r=;
for(int i=;i<=;i++)
{
double mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.6f\n",l);
}
return ;
}

2017 Multi-University Training Contest - Team 4 hdu6070 Dirt Ratio的更多相关文章

  1. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  5. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  8. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. win7win8 64位汇编开发环境合集安装与设置

    win7win8 64位汇编开发环境合集安装与设置 下载 win7 win8  64位汇编开发环境.rar 下载地址(免积分下载) http://download.csdn.net/detail/li ...

  2. 《jquery权威指南2》学习笔记------基础函数

    Math.floor(Math.random() * 7 + 1); Math.random() 生成0和1之间的随机小数Math.random() * 7 生成0和7之间的随机小数Math.rand ...

  3. .net Session延长过期时间

    一.全局网站(即服务器)级 IIS-网站-属性-Asp.net-编辑配置-状态管理-会话超时(分钟)-设置为120,即为2小时,即120分钟后如果当前用户没有操作,那么Session就会自动过期. 二 ...

  4. oracle11g配置dataguard

     DATAGUARD是通过建立一个PRIMARY和STANDBY组来确立其参照关系.      STANDBY一旦创建,DATAGUARD就会通过将主数据库(PRIMARY)的REDO传递给STAND ...

  5. python里的生成器

    author:headsen chen date:2018-03-22 10:59:46 notice:This article created by headsen chen himself and ...

  6. mysql 修改默认配置 提高性能

    解决问题 Lost connection to MySQL server at ‘reading authorization packet’, system error: 0 通过修改 connect ...

  7. android高仿微信UI点击头像显示大图片效果, Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    http://www.cnblogs.com/Jaylong/archive/2012/09/27/androidUI.html http://blog.csdn.net/xiaanming/arti ...

  8. tomcat自动加载class

    转载 tomcat自动加载改变的class文件(无需重启tomcat)  http://blog.csdn.net/miraclestar/article/details/6434164 不重启Tom ...

  9. coderfun-boot接私活利器,文档详实,非一般的开发速度

    项目主页:https://gitee.com/klguang/coderfun-boot 演示地址:http://106.15.195.9:8080/admin/项目文档:https://www.ka ...

  10. 170404、java版ftp操作工具类

    package com.rick.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileNotF ...