题目1434:今年暑假不AC
来源:互联网 发布:windows最新服务器系统 编辑:程序博客网 时间:2024/05/22 12:59
#include<iostream>#include<algorithm>using namespace std; class MyTime{public: int begin; //开始时间 int end; //结束时间 bool operator <(const MyTime &timeA)const //此处const丢了 { return this->end < timeA.end; } bool canPlay(const MyTime &timeB);};bool MyTime::canPlay(const MyTime &timeB){ if(this->end <= timeB.begin) { return true; } else return false;} MyTime times[100]; //记录每场节目起始点 int main(){ int n;//记录n中节目安排 while(cin >> n && 0!=n) { for(int i=0; i<n; i++) { cin >> times[i].begin >> times[i].end; } sort(times,times+n);//对节目进行排序 int cnt =1;//记录可以看的节目数 for(int m=0,j=1; j<n;j++) { //此处犯二了,最开始用的是if(times[j].canPlay(times[j+1])) //也就是一直是前一个后一个,应该是拿已选择观看的节目来与下一个要看的比 //cout << times[j].begin << " " << times[j].end << endl; if(times[m].canPlay(times[j])) { // cout << times[j].begin << " " << times[j].end << endl; cnt ++; m= j; } // else // { // cout << "Hello world" <<endl; // } } cout << cnt <<endl; } return 0;}/************************************************************** Problem: 1434 User: itswyy Language: C++ Result: Accepted Time:10 ms Memory:1520 kb****************************************************************/
0 0
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 22-题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC 题目22
- 九度oj 题目1434:今年暑假不AC
- 九度题目1434:今年暑假不AC
- 题目1434:今年暑假不AC(贪心算法运用)
- 九度 题目1434:今年暑假不AC
- 题目1434:今年暑假不AC[贪心算法]
- 题目1434:今年暑假不AC 九度OJ
- 题目1434:今年暑假不AC ||九度
- 题目22:今年暑假不AC
- 今年暑假不AC?
- 解密回文——栈
- java中判断字符串是否为数字的三种方法
- Android SDK for linux 设置代理
- testlin配合wampserver安装过程记录及问题解决
- 学PHP不能不懂的cookie知识
- 题目1434:今年暑假不AC
- C和C++混合编译
- 高速缓存污染 cache pollution
- MAKEFILE --变量
- Teradata 金融数据模型FS-LDM
- 搭建python+PyQt+Eric平台(东挪西凑反正是完整了)\
- ACE_TMAIN的解析
- javascript原生选择器的一些基本方法
- Mysql Case 使用