CodeForces 589F-Gourmet and Banquet-二分答案
2024-08-27 02:15:43
有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);
}
最新文章
- mac命令
- Python基础-day2
- ASP.NET QueryString乱码解决问题
- order by
- Android自动测试之monkeyrunner工具
- hdu_5738_Eureka(脑洞)
- i春秋与我
- H5 内联 SVG
- 13. ZooKeeper最佳实践
- 分享一个大神自己的blog
- CodeFirst+MySQL+.Net Core配置详情
- 每日算法---Two Sum
- 解题:CF622F The Sum of the k-th Powers
- 【CF1042D】Petya and Array 离散化+树状数组
- Python入门:数据结构的4种基本类型
- P2034 选择数字
- 小程序for循环给里面单独的view加单独的样式
- linux 查看信息-服务器相关
- underscore.js源码研究(4)
- 利用Everything开启http服务测试移动端浏览器环境