TOJ 2894. Meetings(贪心基础)

题目链接:http://acm.tju.edu.cn/toj/showp2894.html


2894.    Meetings
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
Submit   List    Runs   Forum   Statistics

贪心,蛮不错的一道题,好好理解一下:

#include 
#include 
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


你可能感兴趣的:(贪心算法,经典题目)