Description

假设要在足够多的会场里安排一批活动,并希望使用尽可能少的会场。设计一个有效的算法进行安排。(这个问题实际上是著名的图着色问题。若将每一个活动作为图的一个顶点,不相容活动间用边相连。使相邻顶点着有不同颜色的最小着色数,相应于要找的最小会场数。)
编程任务:
对于给定的k个待安排的活动,编程计算使用最少会场的时间表。

Input

输入数据是由多组测试数据组成。每组测试数据输入的第一行有1 个正整数k,表示有k个待安排的活动。接下来的k行中,每行有2个正整数,分别表示k个待安排的活动开始时间和结束时间。时间以0 点开始的分钟计。

Output

对应每组输入,输出的每行是计算出的最少会场数。

Sample Input

5
1 23
12 28
25 35
27 80
36 50

 

Sample Output

3
#include<iostream>
#include
<queue>
using namespace std;
struct Node
{
    
int s;
    
int e;
    friend 
bool operator <(Node a,Node b)
    
{
        
return a.e > b.e;
    }

}
;
int main()
{
    
int n;
    
while(cin>>n)
    
{
        
int *hash = new int[n+1];
        
int t=0,i,maxe,index;
        Node p;
        priority_queue
<Node>Q;
        
for(i=0;i<n;i++)
        
{
            scanf(
"%d%d",&p.s,&p.e);
            Q.push(p);
        }

        p 
= Q.top();
        Q.pop();
        hash[t
++= p.e;
        
while(!Q.empty())
        
{
            p 
= Q.top();
            Q.pop(); 
            maxe 
= 0;
            index 
= 0;
            
for(i=0 ;i<t;i++)
            
{
                
if(p.s >= hash[i] && maxe < hash[i])
                
{
                    maxe 
= hash[i];
                    index 
= i;
                }

            }

            
if(maxe == 0)
                hash[t
++= p.e;
            
else
                hash[index] 
= p.e;
        }

        cout
<<t<<endl;
        delete []hash;
    }

    
return 0;
}