有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-二分答案的更多相关文章

  1. codeforces 589F. Gourmet and Banquet 二分+网络流

    题目链接 给你n种菜, 每一种可以开始吃的时间不一样, 结束的时间也不一样. 求每种菜吃的时间都相同的最大的时间.时间的范围是0-10000. 看到这个题明显可以想到网络流, 但是时间的范围明显不允许 ...

  2. Codeforces 589F Gourmet and Banquet

    A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet kno ...

  3. Codeforces 551C GukiZ hates Boxes 二分答案

    题目链接 题意:  一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头  有m个学生  目标是删除全部石头  一開始全部学生都站在 x=0的地方  每秒钟每一个学生都 ...

  4. CodeForces 779D. String Game(二分答案)

    题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...

  5. Codeforces 825D Suitable Replacement - 贪心 - 二分答案

    You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...

  6. Codeforces 553D Nudist Beach(二分答案 + BFS)

    题目链接 Nudist Beach 来源  Codeforces Round #309 (Div. 1) Problem D 题目大意: 给定一篇森林(共$n$个点),你可以在$n$个点中选择若干个构 ...

  7. Codeforces 1077D Cutting Out(二分答案)

    题目链接:Cutting Out 题意:给定一个n长度的数字序列s,要求得到一个k长度的数字序列t,每次从s序列中删掉完整的序列t,求出能删次数最多的那个数字序列t. 题解:数字序列s先转换成不重复的 ...

  8. 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)

    F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  9. Codeforces 700A As Fast As Possible(二分答案)

    [题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...

  10. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

随机推荐

  1. Linq to XML操作XML文件

    LINQ的类型 在MSDN官方文件中,LINQ分为几种类型: . LINQ to Objects(或称LINQ to Collection),这是LINQ的基本功能,针对集合对象进行查询处理,包括基本 ...

  2. flask 更新数据库

    在做项目的过程中,我们都遇到过,经常需要修改我们数据库的字段,在flask中,是通过ORM(对象关系映射)来创建数据库的,表--->model class,字段---->属性 在flask ...

  3. H5 详情和概要标签

    38-详情和概要标签 概要信息 详情信息 --> 郑伊健 简介:郑伊健,1967年10月4日出生于中国香港,籍贯广东恩平,香港影视演员.流行男歌手.1988年参加新秀歌唱大赛加入无线电视,因拍摄 ...

  4. DAG路径覆盖模型

    概述 路径覆盖模型的特点是DAG中每个点经过且只经过一次,且一条路径覆盖路径上的所有点. 将每个点拆为\(x\)和\(x'\),暂不考虑其实际意义.然后连边\(S\rightarrow x\),\(x ...

  5. A direct formulation for sparse PCA using semidefinite programming

    目录 背景 Sparse eigenvectors(单个向量的稀疏化) 初始问题(low-rank的思想?) 等价问题 最小化\(\lambda\) 得到下列问题(易推) 再来一个等价问题 条件放松( ...

  6. Python类与对象的理解

    注意python的类对象与实例对象的区分 类对象与实例对象是相对的,例如:a=1,那么a就是int的一个实例对象,这里的a相对于int来说,a是实例对象,int是类对象.但是int同时又是type的实 ...

  7. Python学习第十八篇——低耦合函数设计思想

    import json 2 def greet_user(filename): 3 try: 4 with open(filename) as f_obj: 5 username = json.loa ...

  8. 在java中怎样获得当前日期时间

    Calendar cal = Calendar.getInstance();    java.text.SimpleDateFormat sdf = new SimpleDateFormat(&quo ...

  9. react插件包

    react-scoped-style support ie8,ie8+,chrome,firefox,safari does not support css priority (just apply ...

  10. Composer对于第三方包的自动加载

    Composer提供了四种方式的支持,分别是 PSR-0和PSR-4的自动加载(我的一篇文章也有介绍过它们),生成class-map,和直接包含files的方式. PSR-4是composer推荐使用 ...