Codeforces 377B . Preparing for the Contest【优先队列】
来源:互联网 发布:怎样查询电信网络密码 编辑:程序博客网 时间:2024/06/05 14:48
题目大意:
有m个bug,n个学生,每个bug有自己的复杂值,每个学生有自己的能力值,只能解决复杂值小于自己能力值的bug,且每天只能解决一个bug,但是每个学生处理bug需要报酬,问在报酬不超过s的情况下,在最短的时间内,能将bug全部解决完。
做法:
首先明确一点,如果能够解决所有bug,那么解决的天数一定在1~m之间。先判断m天能不能解决,如果不能则输出NO,如果可以再进行下面的操作。
我们可以二分枚举解决问题所需的天数t,将bug的复杂值和同学的能力值按照从大到小的顺序排序。首先先处理最复杂的bug,将能够解决该bug的同学添加到优先队列,让这些同学中要钱最少的一个来解决这些bug,显然,这个同学最多能解决t个bug。然后将该同学弹出队列。再用相同的操作处理剩下的没有解决的bug。如果在过程中队列为空,或者花费大于s,那么直接返回。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define N 100010using namespace std;struct aa{ int sk,f,id; bool operator <(const aa &s)const { return sk<s.sk; }}stu[N],bug[N];struct cmp{ bool operator()(aa &x,aa &y) { return x.f>y.f; }};int n,m,s,ans[N];bool check(int t){ int cur=0; priority_queue<aa,vector<aa>,cmp> que; for(int i=m-1,j=n-1;i>=0;i-=t) { for(;j>=0 && stu[j].sk>=bug[i].sk;j--) que.push(stu[j]); if(que.empty()) return false; cur+=que.top().f; if(cur>s) return false; for(int k=i;k>=max(0,i-t+1);k--) ans[bug[k].id]=que.top().id; que.pop(); } return true;}int main(){ scanf("%d%d%d",&n,&m,&s); for(int i=0;i<m;i++) scanf("%d",&bug[i].sk),bug[i].id=i; for(int i=0;i<n;i++) scanf("%d",&stu[i].sk); for(int i=0;i<n;i++) scanf("%d",&stu[i].f),stu[i].id=i; sort(stu,stu+n); sort(bug,bug+m); if(!check(m)) {printf("NO");return 0;} int lb=0,ub=m+1; while(ub-lb>1) { int mid=(ub+lb)/2; if(check(mid)) ub=mid; else lb=mid; } printf("YES\n"); check(ub); for(int i=0;i<m;i++) cout<<ans[i]+1<<" "; return 0;}
0 0
- Codeforces 377B . Preparing for the Contest【优先队列】
- CodeForces 377B Preparing for the Contest 贪心(二分加优先队列)
- Codeforces 377B Preparing for the Contest【二分查找+优先队列+贪心】
- CodeForces 377 B. Preparing for the Contest
- codeforces 377B Preparing for the Contest
- CodeForces 377B Preparing for the Contest
- CodeForces 337B Preparing for the Contest(二分+贪心+优先队列)
- CodeForces 377B---Preparing for the Contest(二分+贪心)
- CodeForces 377B-Preparing for the Contest(二分+贪心)
- CF377B Preparing for the Contest [贪心+优先队列]
- Codeforces Round #222 (Div. 1) B - Preparing for the Contest
- B. Preparing for the Contest----二分+贪心
- Codeforces Round #346 (Div. 2) B - Qualifying Contest 优先队列
- Codeforces 847B Preparing for Merge Sort
- CodeForces 377B 优先队列 + 二分
- Codeforces 847 B. Preparing for Merge Sort (二分)
- CodeForces 550B Preparing Olympiad
- codeforces-550B-Preparing Olympiad
- 深入Java单例模式
- 启用和自定义 ASP.NET Web API 服务的安全性
- 如何patch Netcdf的jar包
- NYOJ 题目阶乘因式分解(二)(数学)
- 集合中的元素无故被擅改,到底是怎么回事
- Codeforces 377B . Preparing for the Contest【优先队列】
- webapi摘要认证
- 查看虚拟内存的使用
- NYOJ 题目330一个简单的数学题(数学)
- [LeetCode OJ] Word Break 解题报告
- php绝对路径与相对路径之间关系的的深入研究
- Machine Learning Notes - PLA
- 栈与队列的实现__ 两个栈实现队列 vs 两个队列实现栈
- 深入C++的拷贝构造和赋值函数 (深拷贝,浅拷贝)