joj2170

 2170: Travel

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
3s 8192K 495 177 Standard
Mike want to travel around in the holiday, so he found some info. The travel starts at the time S and ends at F. Mike want to do more tavelling without any conflicts in time, namely, each travelling's start time is later than the last's end time. You are to write a program to help him calculate how many trips he can travel at most.

Input

The first line of each test is a integer N (0 < N <= 10000)-the number of the info. Then the next N line follows. Each line contains two integers S(start time)and F(end time).

Output

For each test you should output the number of the max trips .

Sample Input

2
10 15
16 17
2
10 15
15 16

Sample Output

2
1

Problem Source: evilll

This problem is used for contest: 25 





#include<stdio.h>
#include<algorithm>
using namespace std;
struct NODE
{
    int start;
    int end;
};
bool cmp(const NODE &n1,const NODE &n2)
{
    if(n1.end>n2.end)
    return false;
    else
    return true;
}
NODE node[10005];
int main()
{
    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n;i++)
        scanf("%d%d",&node[i].start,&node[i].end);
        sort(node,node+n,cmp);
        int temp=node[0].end;
        int count=1;
        for(int i=1;i<n;i++)
        {
            if(node[i].start>temp)
            {
                temp=node[i].end;
                count++;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}


这个题目主要是比较前一个的结束时间与后一个的开始时间。

你可能感兴趣的:(Integer,ini,input,each,n2,output)