CodeForces 589F-Gourmet and Banquet-二分答案
有m盘菜,每盘有一个开始时间和结束时间,必须每盘都吃同样的时间。问最多能吃多久。
二分答案,然后用一个优先队列维护当前时间内的菜,然后每次都吃结束时间最小的那盘。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue> using namespace std; const int maxn = 1e4+;
const int INF = 0x3f3f3f3f;
int N,len,a[maxn],b[maxn],save[];; struct node
{
int a,b,id;
node(){}
node(int x,int y,int z):a(x),b(y),id(z){}
bool operator < (const node &b) const
{
return a<b.a;
}
}Dish[maxn]; struct node2
{
int ed,id;
node2(int x,int y):ed(x),id(y){}
bool operator < (const node2 &b) const
{
return ed > b.ed;
}
}; int solve(int ll,int rr)
{
int mid = (ll+rr)>>,cnt=;
if(ll+ >= rr) return mid;
priority_queue<node2> q; memset(save,,sizeof save);
//printf("ll:%d rr:%d\n",ll,rr);
for(int cur=;cur<=len;cur++)
{
//printf("cur:%d cnt:%d num:%d\n",cur,cnt,q.size());
while(cnt < N && Dish[cnt].a == cur)
{
q.push(node2(Dish[cnt].b,Dish[cnt].id));
cnt++;
}
//printf("save:%d mid:%d\n",save[q.top().id],mid);
while(!q.empty() && save[q.top().id]>=mid && save[q.top().id])
{
q.pop();
} if(!q.empty()) {/*printf("id:%d++\n",q.top().id);*/save[q.top().id]++;} while(!q.empty() && q.top().ed <= cur+)
{
if(save[q.top().id] < mid || save[q.top().id]==) {/*printf("id:%d save:%d\n",q.top().id,save[q.top().id]);*/return solve(ll,mid==?:mid);}
q.pop();
} if(q.empty()&&cnt==N) return solve(mid,rr);
}
} int main()
{
scanf("%d",&N);
int l = INF,r = -INF;
len = -INF;
for(int i=;i<N;i++)
{
scanf("%d%d",&a[i],&b[i]);
Dish[i] = node(a[i],b[i],i);
r = max(b[i]-a[i],r);
len = max(len,b[i]);
}
sort(Dish,Dish+N);
printf("%d\n",solve(,r+)*N);
}
CodeForces 589F-Gourmet and Banquet-二分答案的更多相关文章
- codeforces 589F. Gourmet and Banquet 二分+网络流
题目链接 给你n种菜, 每一种可以开始吃的时间不一样, 结束的时间也不一样. 求每种菜吃的时间都相同的最大的时间.时间的范围是0-10000. 看到这个题明显可以想到网络流, 但是时间的范围明显不允许 ...
- Codeforces 589F Gourmet and Banquet
A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet kno ...
- Codeforces 551C GukiZ hates Boxes 二分答案
题目链接 题意: 一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头 有m个学生 目标是删除全部石头 一開始全部学生都站在 x=0的地方 每秒钟每一个学生都 ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
- Codeforces 825D Suitable Replacement - 贪心 - 二分答案
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...
- Codeforces 553D Nudist Beach(二分答案 + BFS)
题目链接 Nudist Beach 来源 Codeforces Round #309 (Div. 1) Problem D 题目大意: 给定一篇森林(共$n$个点),你可以在$n$个点中选择若干个构 ...
- Codeforces 1077D Cutting Out(二分答案)
题目链接:Cutting Out 题意:给定一个n长度的数字序列s,要求得到一个k长度的数字序列t,每次从s序列中删掉完整的序列t,求出能删次数最多的那个数字序列t. 题解:数字序列s先转换成不重复的 ...
- 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)
F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- Codeforces 700A As Fast As Possible(二分答案)
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
随机推荐
- [翻译] 如何在 ASP.Net Core 中使用 Consul 来存储配置
[翻译] 如何在 ASP.Net Core 中使用 Consul 来存储配置 原文: USING CONSUL FOR STORING THE CONFIGURATION IN ASP.NET COR ...
- 在vue2.0中引用element-ui组件库
element-ui是由饿了么团队开发的一套基于 Vue 2.0 的桌面端组件库. 官网:http://element.eleme.io/ 安装 npm i element-ui -S 引用完整的el ...
- 朱晔和你聊Spring系列S1E5:Spring WebFlux小探
阅读PDF版本 本文会来做一些应用对比Spring MVC和Spring WebFlux,观察线程模型的区别,然后做一下简单的压力测试. 创建一个传统的Spring MVC应用 先来创建一个新的web ...
- NoSQL是什么?
导读 NoSQL(not only sql,不仅仅是SQL),是一项全新的数据库革命性运动,泛指非关系型数据库,对于NoSQL这个新兴的名词,每个人的理解都不同.其实NoSQL一词最早出现于1998年 ...
- 福州大学软件工程1816 | W班 第2次作业成绩排名
作业链接 词频统计基础功能 评分细则 本次个人项目分数由两部分组成(博客分满分40分+程序得分满分60分) 博客评分规则 在文章开头给出你们Fork仓库的Github项目地址.(1') 在开始实现程序 ...
- 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决方案: 1.查看浏览器当前版本:chrome://version/. 2.到https://sites.google.com/a/chromium.org/chromedriver/downloa ...
- FAIL - Deploy Upload Failed, Exception: [org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (112503036) exceeds the configured
Message: FAIL - Deploy Upload Failed, Exception: [org.apache.tomcat.util.http.fileupload.FileUpload ...
- windows下使用cmake编译zlib与libpng libjpeg
win7下使用VS2010编译jpeglib 1.下载源代码下载地址:http://www.ijg.org/files/, 选择最新版本的windows版本压缩包,进行下载. jpeg ...
- js压箱底的宝贝
框架的确好用, 不过他们也隐藏了JavaScript中丑陋的细节和DOM的运作机制. 如果你的目标是敢于自称"我懂JavaScript", 那么花时间学习框架无异于南辕北辙. 下面 ...
- HDU 5898 odd-even number
题目:odd-even number 链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5898 题意:给一个条件,问l 到r 之间有多少满足条件的 ...