地址: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. PPT如何一页多张打印且铺满整个页面

    最近由于工作需要,有些ppt材料想打印出来学习,但是ppt页数较多,ppt单页打印有些浪费纸张,而且也不能拿到外面打印店去打印,所以只能自己动手设置一页多张打印,并且最后双面打印,这样就做够节省纸张了 ...

  2. jQuery制作简洁的多级联动Select下拉框

    今天我们要来分享一款很实用的jQuery插件,它是一个基于jQuery多级联动的省市地区Select下拉框,并且值得一提的是,这款联动下拉框是经过自定义美化过的,外观比浏览器自带的要漂亮许多.另外,这 ...

  3. char[]与TCHAR[]互相转换引发的一个问题!

      软件的一个驱动由于开发的年代比较久一些,使用的是非Unicode编码,而当前新的软件使用的是Unicode编码,于是将非Unicode驱动用于Unicode软件上时,就出现了问题! 问题就出现在非 ...

  4. Spring_day04--课程安排_回顾SSH框架知识点_SSH框架整合思想

    Spring_day04 上节内容回顾 今天内容介绍 回顾SSH框架知识点 Hibernate框架 Struts2框架 Spring框架 SSH框架整合思想 整合struts2和spring框架 Sp ...

  5. 统计nginx进程占用的物理内存

    #!/usr/bin/env python #-*- coding:utf-8 -*- ''' 统计nginx进程占用的物理内存 ''' import os import sys import sub ...

  6. jquery使用replaceWith替换元素,但是替换的位置不对应的问题

    $("#itemList").replaceWith(htmlContent); 注: $("#itemList")处应为tr元素,如果是span元素或者div ...

  7. 160420、zTree获取所有选中节点数据

    <!DOCTYPE html><HTML><HEAD> <TITLE> ZTREE DEMO - Standard Data </TITLE> ...

  8. JAVA基础之multipart,urlencoded以及JSON

    一.(enctype) 表单的默认编码方式  ajpplication/x-www-form-urlencoded 上传文件的编码方式  multipart/form-data 互联网应用常用编码   ...

  9. CentOS6.7 通过yum在线安装MySQL5.7

    一.安装1.检测系统是否自带安装mysql yum list installed | grep mysql 发现系统自带依赖库:mysql-libs.x86_64 2.删除系统自带的mysql及其依赖 ...

  10. ubuntu重启不清除 /tmp 设置

    gedit /etc/default/rcS, 把TMPTIME=0 修改成 TMPTIME=-1,保存退出即可.