hdu6070 Dirt Ratio 二分+线段树
/**
题目:hdu6070 Dirt Ratio
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070
题意:给定n个数,求1.0*x/y最小是多少。x表示一段区间内不同数字的个数,y表示区间长度。
思路:二分+线段树
二分答案x/y。 找一段区间满足 size(l,r)/(r-l+1) <= mid , size(l,r)表示[l,r]内不同数的个数。 size(l,r)<=mid(r-l+1) => size(l,r)+mid*l<=mid*(r+1); 用线段树维护size(l,r)+mid*l的最小值。每一个节点存储size(l,r)+mid*l,枚举r,更新当前a[r]到不包含该数字的节点值+1 */
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
const double eps = 1e-;
const int N = 6e4+;
double add[N<<], sum[N<<];
int last[N], a[N];
void pushup(int rt)
{
sum[rt] = min(sum[rt<<],sum[rt<<|]);
}
void pushdown(int rt)
{
sum[rt<<] += add[rt];
sum[rt<<|] += add[rt];
add[rt<<] += add[rt];
add[rt<<|] += add[rt];
add[rt] = ;
}
void update(int l,int r,int L,int R,int rt,double d)
{
if(l<=L&&R<=r){
sum[rt]+=d;
add[rt]+=d;
return ;
}
if(add[rt]>eps) pushdown(rt);
int m = (L+R)/;
if(r<=m) update(l,r,lson,d);
else if(l>m) update(l,r,rson,d);
else{
update(l,r,lson,d);
update(l,r,rson,d);
}
pushup(rt);
}
double query(int l,int r,int L,int R,int rt)
{
if(l<=L&&R<=r){
return sum[rt];
}
if(add[rt]>eps) pushdown(rt);
int m = (L+R)/;
double mis;
if(r<=m) mis = query(l,r,lson);
else if(l>m) mis = query(l,r,rson);
else mis = min(query(l,r,lson),query(l,r,rson));
pushup(rt);
return mis;
}
int main()
{
//freopen("C:\\Users\\accqx\\Desktop\\in.txt","r",stdin);
int T, n;
cin>>T;
while(T--)
{
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%d",&a[i]);
double hi = , lo = , mid;
double temp;
while(hi-lo>eps){
mid = (hi+lo)/;
memset(add, , sizeof add);
memset(sum, , sizeof sum);
memset(last, , sizeof last);
int flag = ;
for(int i = ; i <= n; i++){
update(last[a[i]]+,i,,n,,);
update(i,i,,n,,mid*i);
temp = query(,i,,n,);
if(temp<=mid*(i+)){
flag = ; break;
}
last[a[i]] = i;
}
if(flag) hi = mid;
else lo = mid;
}
//cout<<mid<<endl;
printf("%.10f\n",mid);
}
return ;
}
hdu6070 Dirt Ratio 二分+线段树的更多相关文章
- 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 ...
- hdu6070(分数规划/二分+线段树区间更新,区间最值)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 给出一个题目提交序列, 从中选出一个正确率最小的子串. 选中的子串中每个题目当且仅当最 ...
- HDU4614 Vases and Flowers 二分+线段树
分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...
- J - Joseph and Tests Gym - 102020J (二分+线段树)
题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- 【BZOJ-3110】K大数查询 整体二分 + 线段树
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6265 Solved: 2060[Submit][Sta ...
- K-th occurrence HDU - 6704 (后缀数组+二分线段树+主席树)
大意: 给定串s, q个询问(l,r,k), 求子串s[l,r]的第kk次出现位置. 这是一篇很好的题解: https://blog.csdn.net/sdauguanweihong/article/ ...
- 【二分】【线段树】hdu6070 Dirt Ratio
size(l,r)表示区间l,r权值的种类数,让你求min{size(l,r)/(r-l+1)}(1<=l<=r<=n). last[r]表示a[r]上一次出现的位置, 就是二分验证 ...
随机推荐
- MR 文件合并
package com.euphe.filter; import com.euphe.util.HUtils; import com.euphe.util.Utils; import org.apac ...
- block的知识点
// // main.m // 1211块练习 // // Created by jerehedu on 14/12/11. // Copyright (c) 2014年 jereh. All ...
- C#注释——爱你不是两三天
说到注释这个东东,我不得不说:爱你不是两三天,每天却想你很多遍...原来梁静茹同学这首歌不全然是情歌啊~ 一句注释也没有的一大片的代码有木有 看着那些无名者写的神秘代码,有没有骂一句,你妹的... ...
- taro + taro-ui + dva
taro的安装及使用 安装 Taro 开发工具 @tarojs/cli 使用 npm 或者 yarn 全局安装,或者直接使用npx $ npm install -g @tarojs/cli $ yar ...
- Patterns-Flyweight
最近在组里讨论设计模式,第一个是享元模式. 自己贴了一篇这个文章:http://www.cnblogs.com/rush/archive/2011/10/01/2197785.html 感觉这篇讲的不 ...
- Android自动化测试之MonkeyRunner录制和回放脚本
Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...
- Linux-profile、bashrc、bash_profile之间的区别和联系
为使Bash更好地为我们服务,我们需定制bash shell环境. ~/.bash_profile.~/.bashrc.和~/.bash_logout 上面这三个文件是bash shell的用户环境配 ...
- 基于easyui fom分组插件
本插件适用于表单按属性分组,可以动态设置显示的列数,每一个表单宽度,表单类型,以及对齐.不同panel之间的表单也是对齐的. 效果: 依赖:jquery ,easyui, 实现过程:整个控件一个pan ...
- android 模拟器上传文件 Read-only file system
在cmd窗口一条命令就可以了:adb shellmount -o remount rw /
- C#7.0之元组数据
static (string,string,string) LookupName(int a) { return ("","",""); } ...