The 36th ACM/ICPC Asia Regional Fuzhou Site / 1010 War
来源:互联网 发布:汽车保险算法 编辑:程序博客网 时间:2024/06/09 15:30
题目链接
我一开始的想法就是递推,维护一个cover值,表示能用第二阶段等待的时间来帮下一组数据cover掉多少时间。
但是我竟然没有考虑到可以不用等待下一组的第二段时间(即 t 时间)完成而马上进行第三组的 d 时间。这里wa了。
改后艰难AC....残了....
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define MAXN 100005struct node{ int d, t; }a[MAXN];int n;int solve(){int ret=0;int cover=0;for(int i=0; i<n; i++){//debug//printf("go (%d, %d), cover=%d\n", a[i].d, a[i].t, cover);int all = a[i].d+a[i].t;int x = a[i].d+a[i].t - cover;if(x<0)//ȫcover{cover = max(cover-a[i].d, a[i].t);x=0;}else if(cover>a[i].d)//{cover = max(cover-a[i].d, a[i].t);}else {cover = a[i].t;}ret+=x;}return ret;}int cmp(node x, node y){if(x.t>y.t) return 1;else if(x.t==y.t && x.d<y.d) return 1;else return 0;}int main(){int t;scanf("%d", &t);for(int T=0; T<t; T++){printf("Case %d: ", T+1);scanf("%d", &n);for(int i=0; i<n; i++){scanf("%d%d", &a[i].d, &a[i].t);}sort(a, a+n, cmp);printf("%d\n", solve());}}
- The 36th ACM/ICPC Asia Regional Fuzhou Site / 1010 War
- The 36th ACM/ICPC Asia Regional Fuzhou Site / 1001 A Card Game 简证
- The 36th ACM/ICPC Asia Regional Dalian Site 1006 The kth great number
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest Find the maximum
- The 36th ACM/ICPC Asia Regional Dalian Site 1003 The Frog's Games
- The 36th ACM/ICPC Asia Regional Dalian Site 1004 The kth great number
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4001
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4002
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4007
- hdu 4011 The 36th ACM/ICPC Asia Regional Shanghai Site —— WarmupWorking in Beijing
- The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup
- HDU4021 24 Puzzle The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- HDU4023 Game The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- HDU 4034 Graph The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest
- HDU 4038 Stone The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest
- 【转】The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest 出题报告
- The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest
- 实用算法实现-第 17 篇强连通分支
- window.showModalDialog的传值和返回值
- DSP Lib的编写
- 各种排序算法
- 如何求树中的两个节点的最近公共祖先?
- The 36th ACM/ICPC Asia Regional Fuzhou Site / 1010 War
- 游戏服务器端开发要点
- ORACLE +win2003 群集手记
- 微软企业库5.0
- joj2511
- Magic ajax
- 关于linux系统添加或更新源时,报没有公钥,签名无法验证的错误到处理办法
- 有限状态机(修改颜色与格式,方便阅读)
- 网站名称的重要性