题目链接:http://acm.tju.edu.cn/toj/showp2894.html
Time Limit: 3.0 Seconds Memory Limit: 65536K
Total Runs: 2042 Accepted Runs: 599
There are several meeting rooms in Tianjin University. Since there are a lot of new students registering at the beginning of the term, the directors of school have scheduled many meetings to discuss upcoming issues. Suppose there are N meetings in total. The i-th meeting starts at time si and ends at time ei. Consider the j-th meeting can be held immediately after the i-th meeting in the same meeting room. Then we must have sj ≥ ei. In order to minimize usage of resources, the directors of school has asked you to write a program that calculates the minimum number of meeting rooms required for the whole meetings.
Input
There are several test cases in the input data. The first line contains the number of test cases. The first line contains a positive integer N (1 ≤ N ≤ 105) denoting the number of meetings. Then there are N lines, and the i-th line contains si and ei, (1 ≤ si < ei ≤ 109) denoting the start time and the end time of i-th meeting.
Output
Output the minimum number of meeting rooms required for the whole meetings.
Sample Input
2 2 1 3 3 5 3 3 5 1 4 4 5
Sample Output
1 2
Hint: In the second sample input, we can arrange the meeting like this to minimize the number of meeting rooms required:
Room A: (1, 4) (4, 5)
Room B: (3, 5)
Source: TJU Exam 2007
#include <stdio.h>
#include <algorithm>
using namespace std;
#define Max 100001
#define INF 1<<29
int s[Max],e[Max];
int main(){
int cast,n;
scanf("%d",&cast);
while(cast--){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&s[i],&e[i]);
sort(s,s+n);
sort(e,e+n);
int sum=0;
for(int i=0,j=0;i<n;i++)
if(s[i]<e[j])
sum++;
else
j++;
printf("%d\n",sum);
}
}