joj2170
来源:互联网 发布:解剖生理学试题软件 编辑:程序博客网 时间:2024/06/05 06:21
2170: Travel
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
210 1516 17210 1515 16
Sample Output
21
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;
}
这个题目主要是比较前一个的结束时间与后一个的开始时间。