Dirt Ratio

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
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.

 
Source

官方题解:

 

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define bug(x) cout<<"bug"<<x<<endl;
#define eps 1e-4 const int N=6e4+,M=1e6+,inf=;
const LL INF=1e18+,mod=;
struct is
{
double minn[N<<];
int lazy[N<<];
void pushdown(int pos)
{
if(lazy[pos])
{
minn[pos<<]+=lazy[pos];
minn[pos<<|]+=lazy[pos];
lazy[pos<<|]+=lazy[pos];
lazy[pos<<]+=lazy[pos];
lazy[pos]=;
}
}
void build(int l,int r,int pos,double m)
{
lazy[pos]=;
if(l==r)
{
minn[pos]=m*l;
return;
}
int mid=(l+r)>>;
build(l,mid,pos<<,m);
build(mid+,r,pos<<|,m);
minn[pos]=min(minn[pos<<],minn[pos<<|]);
}
void update(int L,int R,int z,int l,int r,int pos)
{
if(L<=l&&r<=R)
{
minn[pos]+=z;
lazy[pos]+=z;
return;
}
pushdown(pos);
int mid=(l+r)>>;
if(L<=mid)update(L,R,z,l,mid,pos<<);
if(R>mid) update(L,R,z,mid+,r,pos<<|);
minn[pos]=min(minn[pos<<],minn[pos<<|]);
}
double query(int L,int R,int l,int r,int pos)
{
if(L<=l&&r<=R)return minn[pos];
pushdown(pos);
int mid=(l+r)>>;
double ans=;
if(L<=mid)ans=min(ans,query(L,R,l,mid,pos<<));
if(R>mid)ans=min(ans,query(L,R,mid+,r,pos<<|));
return ans;
}
}tree;
int n,pre[N],a[N];
int check(double x)
{
tree.build(,n,,x);
memset(pre,,sizeof(pre));
for(int i=;i<=n;i++)
{
tree.update(pre[a[i]]+,i,,,n,);
double p=tree.query(,i,,n,);
//cout<<i<<" "<<x<<" "<<p<<" "<<x*(i+1)<<endl;
if(p<=x*(i+))return ;
pre[a[i]]=i;
}
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
double s=;
double e=,ans=-;
while(e-s>=eps)
{
double mid=(s+e)/;
if(check(mid))
{
ans=mid;
e=mid;
}
else s=mid;
}
printf("%f\n",ans);
}
return ;
}

hdu 6070 Dirt Ratio 线段树+二分的更多相关文章

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

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

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

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

  3. 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 ...

  4. HDU 6070 Dirt Ratio(线段树)

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

  5. hdu 6070 Dirt Ratio

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

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

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

  7. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  8. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  9. HDU 5700 区间交 线段树暴力

    枚举左端点,然后在线段树内,更新所有左边界小于当前点的区间的右端点,然后查线段树二分查第k大就好 #include <cstdio> #include <cstring> #i ...

随机推荐

  1. 3、CentOS 6.5系统安装配置Tomcat 8详细过程

    安装环境:CentOS-6.5 安装方式:源码安装 软件:apache-tomcat-8.0.0.RC3.tar.gz 安装前提 安装tomcat 将apache-tomcat-8.0.0.RC3.t ...

  2. onclick 常用手册

    1.如何去使用onclick来跳转到我们指定的页面/跳转到指定url ☆如果只是在本页显示的话,可以直接用location, 方法如下: ①onclick="javascript:windo ...

  3. 判断是移动端还是PC端

    // 判断是移动端还是PC端 $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USE ...

  4. 监控nginx服务

    转自:http://www.cnblogs.com/silent2012/p/5310500.html 在Nginx的插件模块中有一个模块stub_status可以监控Nginx的一些状态信息,默认安 ...

  5. nginx+php+memcache实现hash一致性memcache 集群

    我们工作中可能会遇到key-value数据库,如果我们面对的不止一台memcache服务器,而是很多台.那么现在就回出现一个问题: 当我们访问nginx服务器的时候,我们会判断memcache中是否有 ...

  6. ssh-keygen 命令

    功能 生成.管理和转换认证密钥,包括 RSA 和 DSA 两种密钥,密钥类型可以用 -t 选项指定.如果没有指定则默认生成用于SSH-2的RSA密钥,系统管理员还可以用它产生主机密钥. 通常,这个程序 ...

  7. rhel 6 version `GLIBC_2.14' not found (required by /usr/lib64/libstdc++.so.6)以及libstdc++.so.6: version GLIBCXX_3.4.18 not found解决办法

    最近在oracle linux 7.3下开发了个应用,发布到rhel 6.5运行的时候,报version `GLIBC_2.14' not found (required by /usr/lib64/ ...

  8. Java版 家政服务 社区服务 家装服务平台 源码 有案例 可定制

    产品说明: 家装服务平台.社区服务平台.服务类型的平台--公司成熟产品 包括工匠注册.资质认证.发布服务产品.会员注册.预约服务.工匠定价.执行服务.服务完毕填写工作日志上传现场照片.会员确认服务.返 ...

  9. kali linux 64bit 2019.1a下启动bbqsql:No module named coros

    kali linux 64bit 2019.1a下bbqsql启动失败,错误: File "/usr/local/lib/python2.7/dist-packages/bbqsql/lib ...

  10. Codeforces 839A Arya and Bran

    Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going ...