HDU 6070 Dirt Ratio【分数规划】【线段树】
来源:互联网 发布:淘宝买家信用 编辑:程序博客网 时间:2024/05/20 00:38
题目来戳呀
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 X problems 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.
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
2017 Multi-University Training Contest - Team 4
题意
求区间数字种类的个数/区间长度的最大值。
想法
假设结果为mid,求mid=
#include<bits/stdc++.h>using namespace std;const int maxn=60010;//const double acc=0.0001;int num[maxn<<2],pos[maxn],a[maxn];double v[maxn<<2];double MID,tmp,L,R;void build(int x,int l,int r){//建树 v[x]=MID*l;//l是每次枚举的左端点,相当于mid*l是已知的 num[x]=0; if(l==r) return; int mid=(l+r)>>1; build(x<<1,l,mid); build(x<<1|1,mid+1,r);}void add(int x,int cnt){//单点更新 v[x]+=cnt; num[x]+=cnt;} void pushdown(int x){//对子节点进行延迟标记 if(num[x]) { add(x<<1,num[x]); add(x<<1|1,num[x]); num[x]=0; }}void update(int x,int l,int r,int pre,int right){//更新每个点 if(pre<=l&&r<=right) { add(x,1);//这道题在区间内未出现过 所以贡献一次 return; } pushdown(x); int mid=(l+r)>>1; if(pre<=mid) update(x<<1,l,mid,pre,right); if((mid+1)<=right) update(x<<1|1,mid+1,r,pre,right); v[x]=min(v[x<<1],v[x<<1|1]);}void query(int x,int l,int r,int right){ //size-mid*l<=(r+1)*mid if(r<=right) { if(tmp>v[x]) tmp=v[x]; return; } int mid=(l+r)>>1; query(x<<1,l,mid,right); if((mid+1)<=right) query(x<<1|1,mid+1,r,right);}int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int k=1; k<=n; ++k) scanf("%d",&a[k]); L=0.0,R=1.0; for(int j=1; j<=24; ++j) { MID=(L+R)/2; build(1,1,n); int i; for(i=1; i<=n; ++i) pos[i]=0;///有问题 下标 for(i=1; i<=n; ++i) { tmp=0x3f3f3f3f;//初始化最大值 update(1,1,n,pos[a[i]]+1,i); query(1,1,n,i); if(tmp-MID*(i+1)<=0)//这里就是公式的转化,size+MID*l-MID*(r+1) break; pos[a[i]]=i; } if(i<=n)R=MID; else L=MID; } printf("%.10f",(L+R)/2); } return 0;}
ps:比较匆忙,比赛完再补一下。而且代码还不是优美的,丑哭QAQ
- HDU-6070 Dirt Ratio(二分+线段树+分数规划)
- HDU 6070 Dirt Ratio【分数规划】【线段树】
- HDU 6070 Dirt Ratio 分数规划 二分 线段树维护区间最值
- 2017多校第4场 HDU 6070 Dirt Ratio 分数规划,线段树
- 2017多校四 1004题 hdu 6070 Dirt Ratio 二分 + 线段树 + 分数规划
- Hdu 6070 Dirt Ratio【分数规划+二分+线段树】好题~好题~
- HDU 6070 Dirt Ratio 线段树 二分
- HDU 6070 Dirt Ratio [二分+线段树]
- hdu 6070 Dirt Ratio 二分,线段树
- hdu 6070 Dirt Ratio(线段树+二分)
- hdu 6070 Dirt Ratio二分 线段树
- HDU 6070 Dirt Ratio 线段树 + 二分
- 【HDU 6070 Dirt Ratio】 二分 & 线段树
- HDU 6070 Dirt Ratio 二分+线段树
- HDU 6070 Dirt Ratio 线段树
- HDU 6070 Dirt Ratio(二分+线段树)
- hdu 6070 Dirt Ratio(二分+线段树维护区间最小值)
- HDU 6070 Dirt Ratio(二分+线段树)
- 51Nod->1419最小公倍数挑战 (数论)
- .NET中获取程序根目录的常用方法介绍
- opencv创建滑动条以及滑动条的位置
- 买单侠微服务的API网关演化之路
- Android 7.0 ActivityManagerService(1) AMS的启动过程
- HDU 6070 Dirt Ratio【分数规划】【线段树】
- Apache Torque连接多个数据库及其使用
- hdu 3292 佩尔方程一系列操作
- 聚簇索引与非聚簇索引的区别
- Bootstrap框架 模态框插件 禁止点击空白处关闭模态框事件
- iOS上传应用到蒲公英分发测试
- 初学JAVA02
- 【phantomjs系列】Phantomjs Api介绍
- 在 Ubuntu16.04 上安装 OpenCV3.2.0