-
输入:
第一行n,有n个招聘会,接下来n行每行两个整数表示起止时间,由从招聘会第一天0点开始的小时数表示。
n <= 1000 。
输出:
最多参加的招聘会个数。
样例输入:
3
9 10
10 20
8 15
样例输出:
2
/* *满足条件的第一个招聘会一定是最早结束的,第二个则一定是第一个招聘会结束后剩余的最早结束的. *所以要先对所有的招聘会结束时间排序 */ #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct E{ int a, b; bool operator <(const E e) const{ return b < e.b; }; }a[1001]; inline int ma(int a, int b){ return a >= b ? a : b; } int main(){ int n, end, count; while(~scanf("%d", &n)){ for(int i = 1; i <= n; i++) scanf("%d%d", &a[i].a, &a[i].b); sort(a + 1, a + 1 + n); count = 0; end = -1; for(int i = 1; i <= n; i++){ if(end <= a[i].a){ end = a[i].b; count++; } } printf("%d\n", count); } return 0; }
原题链接
http://ac.jobdu.com/problem.php?pid=1463
题目描述:
又到毕业季,很多大公司来学校招聘,招聘会分散在不同时间段,小明想知道自己最多能完整的参加多少个招聘会(参加一个招聘会的时候不能中断或离开)。