hdu 6070 Dirt Ratio 线段树+二分
Dirt Ratio
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Special Judge

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''.
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.
5
1 2 1 2 3
For every problem, you can assume its final submission is accepted.
官方题解:

#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 线段树+二分的更多相关文章
- HDU 6070 - Dirt Ratio | 2017 Multi-University Training Contest 4
比赛时会错题意+不知道怎么线段树维护分数- - 思路来自题解 /* HDU 6070 - Dirt Ratio [ 二分,线段树 ] | 2017 Multi-University Training ...
- HDU 6070 Dirt Ratio(分数规划+线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 找出一个区间,使得(区间内不同数的个数/区间长度)的值最小,并输出该值. 思路: 因为是要求$\f ...
- 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 ...
- HDU 6070 Dirt Ratio(线段树)
Dirt Ratio Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Tot ...
- hdu 6070 Dirt Ratio
题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6070 (2017 Multi-University Training Contest - Team ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- HDU 5700 区间交 线段树暴力
枚举左端点,然后在线段树内,更新所有左边界小于当前点的区间的右端点,然后查线段树二分查第k大就好 #include <cstdio> #include <cstring> #i ...
随机推荐
- 前端框架VUE----vue的使用
一.安装 对于新手来说,强烈建议大家使用<script>引入 二. 引入vue.js文件 我们能发现,引入vue.js文件之后,Vue被注册为一个全局的变量,它是一个构造函数. 三.使用V ...
- ES6知识整理(2)--变量的解构赋值
最近准备在业余空闲时间里一边学习ES6,一边整理相关知识.只有整理过的学习才是有效的学习.也就是学习之后要使用和整理成文,才是真正的学到了... 上一篇是一个试水,现在接上. 变量提升 看了下朋友回复 ...
- 管理mycat命令详解
mycat监听两个端口,分别为8066和9066:mycat服务默认的数据端口是8066,而9066端口则是mycat管理端口,用于管理mycat的整个集群状态.监听的端口可以在server.xml配 ...
- python类的__slots__属性、__del__属性、上下文(__enter__和__exit__)、
常规情况下,类的属性字典是共享的,而实例的字典是独立的.如果一个类的属性较少,但是拥有很多的实例,这些实例的属性字典会占用较多的内存空间.对这样的类来说,为了节省内存空间,可以使用__slots__类 ...
- ORACLE 12c 配置PL/SQL 并登录
一.安装12c简易客户端 下载:instantclient-basic-nt-12.2.0.1.0.zip 下载并解压到本地目录D:\app\instantclient_12_2 创建tns连接文件: ...
- 主动攻击:利用ms08_067_netapi进行攻击
利用ms09_053_wins进行攻击 ms08_067漏洞 如果用户在受影响的系统上收到特制的 RPC 请求,则该漏洞可能允许远程执行代码. 在 Microsoft Windows 2000.Win ...
- 【python35.2--图形用户界面EasyGui】
一.猜字游戏 #猜字游戏(从1到10) import easygui as g import random g.msgbox('欢迎进入探险之路!') screct = random.randint( ...
- Git学习笔记---安装与初始化 连接远程版本库
1.Git的安装 sudo apt-get install git 用的是linux(ubuntu)系统,安装非常简单,上面一条命令就够了. 2.初次运行的配置 Git 提供了一个叫做 git con ...
- 用vim + xdebug 来追踪thinkphp的执行过程
tree命令的使用几个有实际应用的参数 -a 这是默认的 -d: 只显式目录, 不需要显式目录下的文件 -L: 列出显式的深度. 当前目录下的所有东西为第一级... 在tp下, 有多个Common但是 ...
- 一些常用的mysql语句实例-以后照写2
specification: 规范, 规格, 产品规范, 产品规格, 技术规范, 产品说明书. 如: create_specification, 等等 创建数据库时, 显式地指明, 字符集: crea ...