贪心基础题-----结构体简单应用

来源:互联网 发布:安卓系统刷windows系统 编辑:程序博客网 时间:2024/05/22 02:01
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 leastri 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 T20 indicating the number of test cases.
There are T cases following. In each case, the first line contains an positive integern105, and n lines follow. In each of these lines, there are 3 integers ri,ei,li, where 0ri,ei,li109.

 

Output
For each test case: output ''Case #x: ans'' (without quotes), wherex 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
233 2 25 100 27 1000 233 10 25 100 27 1000 2
 

Sample Output
Case #1: NOCase #2: YES题意大致是某同学考试,有n门课要复习,第i门课要花费ri小时复习,第i门课会在ei小时后开考并持续li小时,问能否所有课程都复习完输入第一行代表机组测试实例,第二行代表课程数n,接下来n行代表n门课,n行中的每一行依次是 需要复习的时间ri 此门课在ei小时后开考 持续li小时理解题意就好做了
#include<cstdio>#include<algorithm>using namespace std;struct lu{// 定义结构体,成员包括三个int型变量    int m, n, k;}kaoshi[100001];int cmp(lu a, lu b){//  定义sort排序的标准,按照结构体元素n的大小排序    return a.n < b.n;}int main(){    int a, b, kcase = 1;    scanf("%d", &a);    while(a--)    {        scanf("%d", &b);        for(int i = 0; i < b; i++){            scanf("%d%d%d", &kaoshi[i].m, &kaoshi[i].n, &kaoshi[i].k);        }        int ok = 0;        sort(kaoshi, kaoshi + b, cmp);//   按上边定义的标准排序        long long ju = kaoshi[0].m;        for(int i = 0; i < b; i++){            if(kaoshi[i].n - ju < 0){//   有一门距离考试时间与需要复习时间差值小于0则肯定不能完成                ok = 1;                break;            }            ju = kaoshi[i+1].m + kaoshi[i].k + kaoshi[i].n;//  本门课距离开考时间加上考试持续时间加上下门课复习时间 与下门课距开考时间继续比较        }        printf("Case #%d: ", kcase++);        printf(!ok ? "YES\n" : "NO\n");//  这个运算符用着停方便    }    return 0;}


0 0