G. Car Repair Shop(优先队列)
来源:互联网 发布:淘宝退款原因质量问题 编辑:程序博客网 时间:2024/06/06 01:35
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
G. Car Repair Shop
题意:修汽n辆车,每次只能修一辆,每辆车有要求开始修理的时间si,修理需要的时间是di。现在安排修车计划,能在要求时间si修的车按照si时间修,否则便尽量往前安排,时间从1开始。
题解: 维护起始点递增的时间区间,不断加入即可。
其实同A题一样,可以用优先队列维护。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <queue>#include <stack>using namespace std;const int N = 200+10;typedef long long LL;const int INF=0x3f3f3f3f;struct Node{ int l ,r;}a[N],now;bool pan(Node a,Node b){ if(a.l > b.r || a.r < b.l) return true; return false;}bool cmp(Node a, Node b){ return a.l < b.l;}int main(){ int n; scanf("%d",&n); int i ,j; for(i = 0; i < n; i++) { int x,y; scanf("%d%d",&x,&y); if(i == 0) { a[i].l = x; a[i].r = x+y-1; printf("%d %d\n",a[i].l,a[i].r); } else { now.l = x; now.r = x+y-1; sort(a,a+i,cmp); for(j = 0; j < i; j++) { if(!pan(now,a[j])) break; } if(j == i) { a[i] = now; printf("%d %d\n",a[i].l,a[i].r); continue; } now.l = 1; now.r = y; for(j = 0; j < i; j++) { if(pan(now,a[j])) { a[i] = now; printf("%d %d\n",a[i].l,a[i].r); break; } else { now.l = a[j].r+1; now.r = a[j].r+y; } } if(j == i) { a[i] = now; printf("%d %d\n",a[i].l,a[i].r); } } } return 0;}
0 0
- G. Car Repair Shop(优先队列)
- CodeForces 730G Car Repair Shop (优先队列乱搞)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest G. Car Repair Shop(优先队列)
- Codeforces 730G Car Repair Shop
- Codeforces 730G. Car Repair Shop 【map】
- codeforces 730G Car Repair Shop 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- 一个有趣的题目[CF730G|2016ACM NEERC G] Car Repair Shop
- Fence Repair (优先队列)
- POJ 3253 Fence Repair (优先队列)
- POJ 3253 Fence Repair(优先队列)
- POJ 3253 Fence Repair(优先队列)
- poj3253 Fence Repair (优先队列)
- 【POJ】-3253-Fence Repair(优先队列)
- POJ:3253 Fence Repair(优先队列)
- Fence Repair(优先队列) POJ 3253
- poj_3253 Fence Repair(优先队列 / 堆)
- Fence Repair 【优先队列】
- Fence Repair (优先队列)
- BOA在LINUX下搭建
- 项目:Activity返回更新问题
- Hadoop生态圈的介绍
- 数据结构示例之分割字符串
- 白话经典算法系列之六 快速排序 快速搞定
- G. Car Repair Shop(优先队列)
- iOS 在聊天界面通过时间戳得到标准格式的字符串
- 用Matlab录制、读取音频
- java高级练习字母出现多少次
- BZOJ 2151 种树 贪心
- PHP安装UUID模块
- Printer Queue
- 系统计时器如何编写(如何计算程序运行时间)
- VMware 克隆centos虚拟机 网卡配置问题 Device eth0 has different MAC address than expected, ignoring.