HDU5240 Exam







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;
}


   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值