2170: Travel
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 8192K | 422 | 145 | Standard |
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
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int beg;
int en;
};
bool cmp(node x,node y)
{
return x.en<y.en;
}
int main()
{
int n,i,j;
node a[10001];
int b[10001];
while(scanf("%d",&n)==1)
{
for(i=0;i<n;i++) cin>>a[i].beg>>a[i].en;
sort(a,a+n,cmp);
memset(b,0,sizeof(b));
b[0]=1;
int coun=1;
j=0;
for(i=1;i<n;i++)
{
if(a[i].beg>a[j].en)
{
b[i]=1;
j=i;
coun++;
}
else
{
b[i]=0;
}
}
printf("%d/n",coun);
}
return 0;
}