| ||||||||||
| 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,請大神們指教In Reply To:Re:discuss所有有的数据,baidu能搜到数据全测了一遍都过,后来发现原来wa在这 Posted by:OYBDOOO at 2018-08-18 01:01:46 #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
struct nod
{
int a,b;
}sz[25005];
bool operator < (const nod&xx,const nod&yy)
{
return xx.a<yy.a;
}
int main()
{
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
int n,t,i;
//scanf("%d %d",&n,&t);
cin>>n>>t;
for(i=1;i<=n;i++)
{
nod gogo;
int x,y;
scanf("%d %d",&x,&y);
gogo.a=x;
gogo.b=y;
sz[i]=gogo;
}
sort(sz+1,sz+n+1);
int s=0,e=0;
int cnt=0;
bool flag=0;
for(i=1;i<=n;i++)
{
if(i==1&&sz[i].a>1)
{
cout<<"-1";
flag=1;
break;
}
if(i==1&&sz[i].a==1)
{
cnt++;
s=1;
e=sz[i].b;
continue;
}
if(i==n&&sz[i].b<t)
{
cout<<"-1";
flag=1;
break;
}
if(sz[i].a>e+1)
{
cout<<"-1";
flag=1;
break;
}
if(sz[i].a<=s&&sz[i].b>e)
{
e=sz[i].b;
continue;
}
if(sz[i].a>s&&sz[i].b>e)
{
cnt++;
s=e+1;
e=sz[i].b;
continue;
}
}
if(!flag)
cout<<cnt;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator