贪心基础题-----结构体简单应用
来源:互联网 发布:安卓系统刷windows系统 编辑:程序博客网 时间:2024/05/22 02:01
Problem Description
As this term is going to end, DRD needs to prepare for his final exams.
DRD hasn 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.
DRD has
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 integern≤105 , and n lines follow. In each of these lines, there are 3 integers ri,ei,li , where 0≤ri,ei,li≤109 .
There are T cases following. In each case, the first line contains an positive integer
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
- 贪心基础题-----结构体简单应用
- 贪心算法简单应用
- 基础贪心(简单)
- 结构体的简单应用
- 简单的贪心。注意用结构体排序!!
- 52-结构体的最简单应用
- 结构体的简单应用HDU4584
- HDU4584结构体的简单应用
- C语言结构体简单应用范例
- 结构体数组的超简单应用
- 结构体——结构体简单应用
- 贪心基础题总结
- 基础结构及其应用实现
- hdu1009简单数据结构-结构体&贪心比例最大以及sort快速排序
- HDU:2037 今年暑假不AC(简单贪心+结构体)
- 基于结构体的混合类型简单应用
- vector与结构体结合的简单应用
- 简单结构体的应用(商品排序C语言)
- Java时时调度(一)
- 第一篇技术博客,给自己设立个目标
- 场景模型的获取与播放模型动画
- Valid Parentheses LeetCode java
- 概要设计
- 贪心基础题-----结构体简单应用
- MySQL函数之日期和时间函数
- PHP命名空间(namespace)的使用详解
- oracle数据库OracleDBconsole服务无法启动的原因及其解决思路
- 访问外网设置代理IP
- 学习MongoDB(四)——Master/Slave模式
- C中操作文件的几种模式
- Visual Studio中Debug与Release编译模式的区别以及Preprocesor directives的使用
- MYSQL 索引及优化