http://acm.hdu.edu.cn/showproblem.php?pid=5240
哎 不多说了 比赛的时候被这题折磨的不轻 深刻认识到自己水平还是相当的low!!!
问题:DRD能不能通过全部的考试
前提:如果他能在这个科目考试之前将这个科目复习完那么他就能通过这个科目的考试
所以我们要解决的就变成了能不能在考试前复习完这个科目
思路:按照时间顺序 用 到目前科目考试剩余的时间-之前复习用过的总时间-之前考试占用的总时间=剩余的时间
比较 剩余的时间是否大于这个科目复习需要的时间 是则可以复习完
代码如下:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int count1[100005];
int count2[100005];
struct node{
int a;
int b;
int c;
}st[100005];
bool cmp(node x,node y){
return x.b<y.b;
}
int main (){
int t;
scanf ("%d",&t);
int Case=1;
while (t--){
int n;
scanf ("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d%d%d",&st[i].a,&st[i].b,&st[i].c);
}
sort(st+1,st+n,cmp);// 一定要排序 给出的科目考试时间不一定按顺序 但是我们计算是按照时间顺序的
memset(count1,0,sizeof(count1));
memset(count2,0,sizeof(count2));
for (int i=1;i<=n;i++){
count1[i]+=count1[i-1]+st[i].a;// 记录总的复习用时
count2[i]+=count2[i-1]+st[i].c;// 记录总的考试用时
}
int flag=1;
for (int i=1;i<=n&&flag;i++){
if (st[i].b-count1[i-1]-count2[i-1]<st[i].a){// 是否可以复习完
flag=0;
}
}
if (flag){
printf ("Case #%d: YES\n",Case);
}
else
printf ("Case #%d: NO\n",Case);
Case++;
}
return 0;
}