1004 problem E
2016-03-15 17:47
253 查看
1004 problem E
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
最简单的那个贪心问题
// 1004.cpp : 定义控制台应用程序的入口点。 // //#include "stdafx.h" #include<iostream> #include<vector> #include<algorithm> #include<fstream> using namespace std; struct program { int x; int y; }b; bool cmp(program &a, program &b) { return a.y < b.y; return a.x < a.x; } int main() { //fstream cin("E:\C++\IN\aaa.txt"); vector<program> p; //fstream cin("E:/C++/IN/aaa.txt"); int a=0; //cin >> a; int j = 1; //if (a == 0) return 0; while (cin >> a&&a!=0) { j = 1; p.clear(); int n = a; while (a--) { cin >> b.x >> b.y; p.push_back(b); } sort(p.begin(), p.end(), cmp); int m = p[0].y; for (int i = 1;i < n;i++) { if (p[i].x >= m) { m = p[i].y;j++; } //cout << "j" << j << "i" << i << endl; } cout << j << endl; } return 0; }
相关文章推荐
- 全志(allwinner)开发心得
- man 3 getaddrinfo
- 静默调用ShellContextMenu 实现QQ文件共享
- mysql心得
- 委托和协议
- hdu 5643 King's Game (dp约瑟夫环)
- mysql心得
- nginx中的if嵌套
- phpstorm小总结
- 模板模式(7)
- iOS本地推送
- Eclipse代码提示功能失效
- 细说Angular ng-class
- MAC中在eclipse luna上搭建移动平台自己主动化測试框架(UIAutomator/Appium/Robotium/MonkeyRunner)关键点记录
- 从jvm源码解读Java运行时的类加载
- 安装mysql时 Write configuration file 错误的解决办法
- hdu 2089 不要62
- 基于java web的博客平台(六)
- MySQL查询:查询一个表中类别字段中Max()最大值对应的记录
- 我们的产品终于入驻淘宝服务市场