有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. MySQL表结构变更,不可不知的Metadata Lock

    在线上进行DDL操作时,相对于其可能带来的系统负载,其实,我们最担心的还是MDL其可能导致的阻塞问题. 一旦DDL操作因获取不到MDL被阻塞,后续其它针对该表的其它操作都会被阻塞.典型如下,如阻塞稍久 ...

  2. MVC简单用户登录授权认证

    1.控制器上面用 [Authorize] 属性标识,表示当前控制器内的所有函数需要用户认证才能访问 2.函数上面用 [AllowAnonymous] 属性标识,表示当前函数不需要用户认证可以直接访问 ...

  3. Windows Community Toolkit 3.0 - UniformGrid

    概述 UniformGrid 控件是一个响应式的布局控件,允许把 items 排列在一组均匀分布的行或列中,以填充整体的可用显示空间,形成均匀的多个网格.默认情况下,网格中的每个单元格大小相同. 这是 ...

  4. Day1 Numerical simulation of optical wave propagation之标量衍射理论基本原理(一)

    <Numerical simulation of optical  wave propagation>内容 1. 介绍光波传输的基础理论.离散采样方法.基于MATLAB平台的编码实例以及具 ...

  5. JS典记

        var href = "";     //遍历a标签     $ ( "a"). each (function () {         href = ...

  6. 在网站开发时,可以设置防盗,不被复制和F12

    禁止小功能 //禁止右键 document.oncontextmenu = function () { return false } //禁止f12 document.onkeydown = func ...

  7. jmeter分布式压测(多台电脑一起压测)

    (1)在Windows下运行 操作步骤: 1)     有多台电脑,每台电脑上都有jmeter,而且这几台电脑都互相能ping通. 2)     在我的电脑的jmeter的配置文件bin目录下的jme ...

  8. c# winform导出Excel

    //需要注意添加引用Microsoft.Office.Interop.Excel.dll string fileName =DateTime.Now.Year+ DateTime.Now.Month+ ...

  9. IdentityServer4【Topic】之登出

    Sign-out 登出 IdentityServer的登出就像删除认证cookie一样简单,但是为了完成一个完整的联合签名,我们必须考虑将用户从客户端应用程序中(甚至可能是上游的Identity提供者 ...

  10. Oracle 同义词(Synonym)

    同义词(Synonym)是表.索引.视图等模式对象的一个别名.通过模式对象创建同义词,可以隐藏对象的实际名称和所有者信息,隐藏分布式数据库中远程对象的设置信息,由此为对象提提供一定的安全性保证.同义词 ...