CodeForces 337B Preparing for the Contest(二分+贪心+优先队列)
来源:互联网 发布:php 表示根目录 编辑:程序博客网 时间:2024/05/22 09:44
题目链接:CodeForces 337B Preparing for the Contest
题目大意:有n个人,m个病毒,s张通行证,然后给出m个病毒的等级,n个人的等级,以及n个人去杀病毒所需要的通行证数量,问所最少花费几天可以杀光病毒,并输出每个病毒被那一个人所清理。PS:人要杀病毒必须等级大于等于病毒,一个人只需支付一次通行证。
解题思路:二分+贪心+优先队列。二分天数,贪心判断,每次用可以杀除当前最高等级病毒中通行证所需最少的。杀mid个大的病毒,优先队列进行优化。
#include <stdio.h>#include <string.h>#include <queue>#include <algorithm>using namespace std;const int N = 100005;struct state {int id, val, pass;friend bool operator <(const state& a, const state& b) {return a.pass > b.pass;}}p[N], bug[N];int n, m, s;bool cmp(const state& a, const state& b) {return a.val > b.val;}void init() {scanf("%d%d%d", &n, &m, &s);for (int i = 0; i < m; i++) {scanf("%d", &bug[i].val); bug[i].id = i;}for (int i = 0; i < n; i++) scanf("%d", &p[i].val);for (int i = 0; i < n; i++) {scanf("%d", &p[i].pass);p[i].id = i;}sort(p, p + n, cmp);sort(bug, bug + m, cmp);}bool judge(int k) {int a = 0, b = 0, sum = s;priority_queue<state> que;while (b < m) {while (a < n) {if (p[a].val >= bug[b].val) que.push(p[a]);else break;a++;}if (que.empty()) return false;state c = que.top(); que.pop();if (sum < c.pass) return false;sum -= c.pass;b += k;}return true;}void put(int k) {int a = 0, b = 0;int ans[N];priority_queue<state> que;while (b < m) {while (a < n) {if (p[a].val >= bug[b].val) que.push(p[a]);else break;a++;}state c = que.top(); que.pop();int t = min(m, b + k);for (int i = b; i < t; i++)ans[bug[i].id] = c.id + 1;b += k;}printf("%d", ans[0]);for (int i = 1; i < m; i++) printf(" %d", ans[i]);printf("\n");}void solve() {if (!judge(m)) {printf("NO\n"); return;}int l = 0, r = m;while (l < r) {int mid = (l + r) / 2;if (judge(mid)) r = mid;else l = mid + 1;}printf("YES\n");put(r);}int main() {init();solve();return 0;}
1 0
- CodeForces 337B Preparing for the Contest(二分+贪心+优先队列)
- CodeForces 377B Preparing for the Contest 贪心(二分加优先队列)
- Codeforces 377B Preparing for the Contest【二分查找+优先队列+贪心】
- CodeForces 377B-Preparing for the Contest(二分+贪心)
- Codeforces 377B . Preparing for the Contest【优先队列】
- CodeForces 377B---Preparing for the Contest(二分+贪心)
- B. Preparing for the Contest----二分+贪心
- CF377B Preparing for the Contest [贪心+优先队列]
- CodeForces 377 B. Preparing for the Contest
- codeforces 377B Preparing for the Contest
- CodeForces 377B Preparing for the Contest
- Codeforces Round #222 (Div. 1) B - Preparing for the Contest
- Codeforces 847 B. Preparing for Merge Sort (二分)
- codeforces 835B The number on the board (优先队列,贪心)
- CodeForces 377B 优先队列 + 二分
- codeforces 725D Contest Balloons(贪心+优先队列)
- Codeforces Round #346 (Div. 2) B - Qualifying Contest 优先队列
- 【二分优化】Preparing for Merge Sort CodeForces
- android通过反射代替R来获取控件对象
- jxl读取excel
- CodeForces 337C Captains Mode(dp+位运算+贪心)
- 11572 - Unique Snowflakes(two pointer)
- LeetCode OJ:Wildcard Matching
- CodeForces 337B Preparing for the Contest(二分+贪心+优先队列)
- 我们如何进行代码审查
- USACO Section 3.2 Stringsobits
- CodeForces 377A Maze(暴力)
- 沉鱼
- Java Mysql 初级操作
- VC _T和L
- CodeForces 378A Playing with Dice(水题)
- 获取客户端ip地址方法和通过curl在命令行提交post数据到服务器