-
题目描述:
-
又到毕业季,很多大公司来学校招聘,招聘会分散在不同时间段,小明想知道自己最多能完整的参加多少个招聘会(参加一个招聘会的时候不能中断或离开)。
-
输入:
-
第一行n,有n个招聘会,接下来n行每行两个整数表示起止时间,由从招聘会第一天0点开始的小时数表示。
n <= 1000 。
-
输出:
-
最多参加的招聘会个数。
-
样例输入:
-
3 9 10 10 20 8 15
-
样例输出:
-
2
-
#include <iostream> #include <algorithm> #include <stdio.h> using namespace std; int n; struct Node { int s, e; } nodes[1001]; bool cmp(const Node & n1, const Node & n2) { return n1.e < n2.e; } int opt[1001]; int main() { while(cin >> n) { for(int i=0; i<n; i++) { cin >> nodes[i].s >> nodes[i].e; opt[i] = 0; } sort(nodes, nodes+n, cmp); opt[0] = 1; for(int i=1; i<n; i++) { for(int j=i-1; j>=0; j--) { if(nodes[i].s >= nodes[j].e) { opt[i] = opt[j]+1; break; } } if(opt[i] < opt[i-1]) { opt[i] = opt[i-1]; nodes[i].e = nodes[i-1].e; } } cout << opt[n-1] << endl; } return 0; } /************************************************************** Problem: 1463 User: coder Language: C++ Result: Accepted Time:10 ms Memory:1532 kb ****************************************************************/