hdu2037
2014-03-19 20:34
225 查看
今年暑假不AC
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24772 Accepted Submission(s): 12975
Problem Description
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%...”
确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
Input
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
Output
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
Sample Input
12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0
Sample Output
5
代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct { int s; int e; }Node; Node a[110]; int count; int cmp(const void *p, const void *q) { int x =(int)((Node *)p)->e; int y = (int)((Node *)q)->e; return x - y; } int main() { int n, num,i; while(scanf("%d", &n), n) { count = 0; memset(a, 0, sizeof(a)); num = 1; for(i = 0; i < n; i++) { scanf("%d%d", &a[i].s, &a[i].e); } qsort(a, n, sizeof(Node), cmp); for(i = 1; i < n; i++) { if(a[i].s >= a[count].e) { num++; count = i; } } printf("%d\n",num); } return 0; }
相关文章推荐
- 敏捷软件开发综述
- 求二维数组最大子数组之和(不能运行)
- Access denied with payslip工资条非同部门员工不能创建bug
- 给定2个数字,n,m,使得从1到n之间的数字组合,他们的和等于m,求所有组合
- 全排列函数 next_permutation()
- Android 系统应用Setting开发小结
- poj Wireless Network(基础并查集)
- Xcode编译异常 Apple Mach-o Linker Error ld: symbol(s) not found for architecture i386
- 华为2014年机试样题 求最大递增数
- windows如何查看端口占用情况
- 第二周作业-程序编写
- 跨进程访问(AIDL服务)—Service(三)
- 敏捷软件方法综述
- HDU 2844 Coins(多重背包)
- Android 利用 Webservice 获取手机号码归属地
- 使用PHP代码对Mysql数据库的数据表显示实例代码
- shell中的${},##和%%的使用
- 图像处理程序,在状态栏显示图像尺寸
- shell中的${},##和%%的使用
- WINCLASS类简介