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. js发送post请求下载文件

    大家都知道ajax是不能直接下载文件的,所以一般都是通过一个超链接的形式去下载一个文件 但是当牵扯到需要发送很多数据到服务器上再下载的时候超链接的形式就有些太过勉强了 如下是一个工具方法(依赖jque ...

  2. border-radius 知识点

    border-radius:50px; 边框半径 CSS度量值都:em.px.百分比如果设置1个值,表示4个圆角都使用这个值.如果设置两个值,表示左上角和右下角使用第一个值,右上角和左下角使用第二个值 ...

  3. sql 月初和月末

    --月初 select  convert(varchar(10),dateadd(day,-(day(getdate()) -1),getdate()) ,120) --月末select  conve ...

  4. objective-C学习笔记(十)协议

    协议 Protocol 协议是类的合同约定,只描述外部接口,不提供具体实现.所以,协议其实可以写在类的.h文件中,不去实现就可以了. 协议可以包含以下成员: 属性 (编译器不会和普通interface ...

  5. java线程的使用(Runnable)

    在实际项目开发过程中,线程是经常要用到的,特别是为了不影响项目的运行效果. 以下就以实际项目中的简单例子来介绍: public class SystemRedisInfoController exte ...

  6. BZOJ 1489: [HNOI2009]双递增序( dp )

    dp(i, j)表示选第i个, 且当前序列长度为j, 另一个序列的最后一个元素的最小值...然后根据上一个是哪个序列选的讨论一下就行了...奇怪的dp... --------------------- ...

  7. BZOJ 1044: [HAOI2008]木棍分割(二分答案 + dp)

    第一问可以二分答案,然后贪心来判断. 第二问dp, dp[i][j] = sigma(dp[k][j - 1]) (1 <= k <i, sum[i] - sum[k] <= ans ...

  8. SignaLR通信技术

    新建MVC项目 如果没有Signale需要使用NuGet安装Signalr namespace SignaLrDemo { public class ChatHub : Hub { public vo ...

  9. JetBrains PhpStorm 使用

    · 在左侧显示当前文件位置 在左侧显示当前文件位置 alt + F1 在选择第1个在文件夹显示文件 在文件标签上 ctrl + 鼠标左键 或者 alt + F1 在选择第8个显示当前文件的函数,变量 ...

  10. SQLITE 多进程查询出错database is locked

    程序比较简单: 父进程查询数据库A表,没有更新操作 子进程同时查询数据库A表,查询出来的内容更新B表. 两个进程都放到while(1)循环中,速度慢的话就是2S执行一次就没有错,执行的速度快的话就会报 ...