Exam

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1028    Accepted Submission(s): 510

Problem Description
As this term is going to end, DRD needs to prepare for his final exams.

DRD has n exams. They are all hard, but their difficulties are different. DRD will spend at least ri hours on the i-th course before its exam starts, or he will fail it. The i-th course's exam will take place ei hours later from now, and it will last for li hours. When DRD takes an exam, he must devote himself to this exam and cannot (p)review any courses. Note that DRD can review for discontinuous time.

So he wonder whether he can pass all of his courses.

No two exams will collide. 

 
Input
First line: an positive integer T≤20 indicating the number of test cases.
There are T cases following. In each case, the first line contains an positive integer n≤105, and n lines follow. In each of these lines, there are 3 integers ri,ei,li, where 0≤ri,ei,li≤109.

 
Output
For each test case: output ''Case #x: ans'' (without quotes), where x is the number of test cases, and ans is ''YES'' (without quotes) if DRD can pass all the courses, and otherwise ''NO'' (without quotes).

 
Sample Input
2
3
3 2 2
5 100 2
7 1000 2
3
3 10 2
5 100 2
7 1000 2
 
Sample Output
Case #1: NO
Case #2: YES
 题解:简单贪心,模拟一下;
代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+;
struct Node{
int r,e,l;
};
Node dt[MAXN];
int cmp(Node a,Node b){
return a.e<b.e;
}
int main(){
int T,N,cnt=;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i=;i<N;i++)
scanf("%d%d%d",&dt[i].r,&dt[i].e,&dt[i].l);
sort(dt,dt+N,cmp);
int flot=,tim=;
for(int i=;i<N;i++){
tim+=dt[i].r;
if(tim>dt[i].e){
flot=;break;
}
tim+=dt[i].l;
}
if(!flot)printf("Case #%d: NO\n",++cnt);
else printf("Case #%d: YES\n",++cnt);
}
return ;
}

Exam(贪心)的更多相关文章

  1. POJ 3110 Jenny's First Exam (贪心)

    题意:告诉你n 个科目的考试日期,在考试当天不能复习,每一个科目的最早复习时间不能早于考试时间的t天,每一天你可以复习完一科,也只能复习一科,求最晚的复习时间!. 析:由于题目给定的时间都在1900 ...

  2. CF-1093 (2019/02/10)

    CF-1093 1093A - Dice Rolling 输出x/2即可 #include<bits/stdc++.h> using namespace std; int main() { ...

  3. Codeforces Edu Round 56 A-D

    A. Dice Rolling 把\(x\)分解为\(a * 6 + b\),其中\(a\)是满6数,\(b\)满足\(1 <= b < 6\),即可... #include <io ...

  4. ZOJ-3721 Final Exam Arrangement 贪心

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 容易的贪心题,排个序.. //STATUS:C++_AC_ ...

  5. hdu 5240 Exam(贪心)

    Exam Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. zoj 3721 Final Exam Arrangement【贪心】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 来源:http://acm.hust.edu.cn/vjudg ...

  7. Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. codeforces 1282C. Petya and Exam (贪心)

    链接:https://codeforces.com/contest/1282/problem/C 题意:  有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a:另一种是困难题,每道题耗 ...

  9. 【HDOJ6651】Final Exam(贪心)

    题意:有n门课,价值之和为m,每门课的价值可能是0到m 一门价值为x的课需要花至少x+1时间准备才能通过 问不管价值如何分配都能通过至少k门课的最小总准备时间 m,n,k<=1e9 思路: #i ...

随机推荐

  1. javascript数字验证输入

    javascript数字验证功能: <html> <body> <p>请输入数字.如果输入值不是数字,浏览器会弹出提示框.</p> <input ...

  2. 笔记-Nodejs中的核心API之Events

    最近正在学习Node,在图书馆借了基本关于Node的书,同时在网上查阅资料,颇有收获,但是整体感觉对Node的理解还是停留在一个很模棱两可的状态.比如Node中的模块,平时练习就接触到那么几个,其他的 ...

  3. C#线程(一)

    本篇作为自己简要的笔记和整理,自己英语略渣  就不翻译了 参考http://www.albahari.com/threading 这里有翻译的http://www.cnblogs.com/miniwi ...

  4. Mybatis学习之JDBC缺陷

    1.JDBC存在的问题 1.将sql语句硬编码到java代码中,如果修改sql语句,需要修改java代码,重新编译.系统可维护性不高. 设想如何解决?(将sql单独 配置在配置文件中) 2.数据库连接 ...

  5. 利用fitnesse实现api接口自动化测试

    上午在园子里乱逛,看了不少小伙伴们分享的接口测试方面的知识,仔细想想,我做接口测试也有几个年头了,大家所叙述到的一些经验或多或少,我也曾遇到过,突然意识到知识的点滴积累是多么的重要,我记得我最早接触接 ...

  6. hdu 4704 Sum 费马小定理

    题目链接 求2^n%mod的值, n<=10^100000. 费马小定理 如果a, p 互质, 那么a^(p-1) = 1(mod p)  然后可以推出来a^k % p = a^(k%(p-1) ...

  7. 12-C语言字符串

    目录: 一.字符串 二.字符串输入输出函数 三.指针数组(字符串数组) 回到顶部 一.字符串 1 一组字符数组,以数组的首地址开始,以ASC码的'\0'结束. 2 字符串与普通数组的区别:普通数组没有 ...

  8. Asp.net Role manager tutorial

    It is very useful in .net we can user framework provided role manager, and easily configure in Web.C ...

  9. ISO/IEC 14443协议浅谈

    一. 非接触IC卡简介 非接触IC卡又称射频卡,是射频识别技术和IC卡技术有机结合的产物.它解决了无源(卡中无电源)和免接触这一难题,具有更加方便.快捷的特点,广泛用于电子支付.通道控制.公交收费.停 ...

  10. 如何修改Protel99SE原理图的标题栏

    本文主要讲述了如何修改Protel99SE原理图中的标题栏内容,使用者可以根据需要修改. 标题栏的格式: 1.添加模板:(1)菜单栏Design\Template\Set Template File ...