| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA得我伤心了啊,有人可以帮我看看吗?#include<stdio.h>
#include<iostream>
using namespace std;
typedef struct line
{
int x;
int y;
}line;
line a[25010];
int cmp(const void *a,const void *b)
{
return (*(line*)a).x-(*(line*)b).x;
}
int main()
{
int n,t,i,tmp,na=0,count=0,flg,ty;
scanf("%d %d",&n,&t);
for(i=0;i<n;i++)
scanf("%d %d",&a[i].x,&a[i].y);
qsort(a,n,sizeof(a[0]),cmp);
tmp=0;
i=0;
while(tmp<t&&i<=n)
{
flg=0;
while(a[i].x<=tmp+1)
{
flg=1;
if(a[i].y>ty)
ty=a[i].y;
i++;
}
count++;
if(!flg)
{
na=1;
break;
}
tmp=ty;
}
if(na)
{
printf("-1\n");
return 0;
}
printf("%d\n",count);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator