有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);
}

最新文章

  1. mac命令
  2. Python基础-day2
  3. ASP.NET QueryString乱码解决问题
  4. order by
  5. Android自动测试之monkeyrunner工具
  6. hdu_5738_Eureka(脑洞)
  7. i春秋与我
  8. H5 内联 SVG
  9. 13. ZooKeeper最佳实践
  10. 分享一个大神自己的blog
  11. CodeFirst+MySQL+.Net Core配置详情
  12. 每日算法---Two Sum
  13. 解题:CF622F The Sum of the k-th Powers
  14. 【CF1042D】Petya and Array 离散化+树状数组
  15. Python入门:数据结构的4种基本类型
  16. P2034 选择数字
  17. 小程序for循环给里面单独的view加单独的样式
  18. linux 查看信息-服务器相关
  19. underscore.js源码研究(4)
  20. 利用Everything开启http服务测试移动端浏览器环境

热门文章

  1. 朱晔的互联网架构实践心得S1E2:屡试不爽的架构三马车
  2. 二十二:制作app的时候超出部分不能滑动
  3. Python_老男孩练习题1
  4. c++入门之类——进一步剖析
  5. anaconda 出现add 。。。进不去
  6. Of Study
  7. Redis趣谈一则
  8. [2017BUAA软工助教]案例分析小结
  9. CodeForces Round #550 Div.3
  10. git repository description