HDU 2027
题目链接:http://hdu.hustoj.com/showproblem.php?pid=2037
区间问题
#include<iostream> #include<algorithm> using namespace std; int main() { int n; while (cin >> n,n) { int *begin = new int[n]; int *end = new int[n]; pair<int, int> *st = new pair<int, int>[n];//Object obj = new Object[N] for (int i = 0; i < n; i++) { cin >> begin[i] >> end[i]; st[i].first=end[i]; st[i].second = begin[i]; } sort(st, st + n);//排序 int ans = 0, t = 0;//结束时间t为0 for (int i = 0; i < n; i++) { if (t <= st[i].second)//结束时间t小于第i个节目的开始时间 { ans++;// 能看的节目数+1 t = st[i].first;//把这个节目的结束时间赋给t } } cout << ans << endl; delete[] begin;//释放 delete[] end; delete[] st; } return 0; }