| ||||||||||
| 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 | |||||||||
测了N组数据不知道为什么WA,那位兄弟能帮忙开你一下指点一下啊#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
#define maxn 25005
int N,T;
struct bow{
int start;
int end;
}cow[maxn];
int used[maxn];
int cmp(const void*a,const void*b)
{
struct bow *c=(bow*)a;
struct bow *d=(bow*)b;
if(c->end!=d->end) return d->end-c->end;
else return c->end-d->end;
}
void read()
{
int i;
for(i=0;i<N;i++)
scanf("%d%d",&cow[i].start,&cow[i].end);
qsort(cow,N,sizeof(cow[0]),cmp);
/*for(i=0;i<N;i++)
cout<<cow[i].start<<' '<<cow[i].end<<endl;*/
}
void solve()
{
int i,op,num,j;
int start,end;
int temp,tempj;
int dur,min=0x7fffffff;
bool flag=0;
if(cow[0].end<T)
{
printf("-1\n");
return;
}
for(i=0;i<N;i++)
{
if(cow[i].start==1)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("-1\n");
return;
}
for(i=0;i<N;i++)
{
if(cow[i].end!=T)
{
op=i;//找出所有可能成立的解
break;
}
}
//cout<<op<<endl;
for(i=0;i<op;i++)
{
memset(used,0,sizeof(used));
num=1;
used[i]=1;
dur=cow[i].end-cow[i].start+1;
start=cow[i].start;
end=cow[i].end ;
if(dur==T)
{
printf("%d\n",num);
return;
}
else{
bool flag=0;
int count=0;
while(start!=1)
{
count=0;
for(j=N-1;j>=0;j--)
{
if(cow[j].start<start&&cow[j].end>=start-1&&used[j]==0)
{
if(count==0)
{
temp=cow[j].start;
tempj=j;
count++;
}
else
{
if(cow[j].start<temp)
{
temp=cow[j].start;
tempj=j;
count++;
}
}
}
}
if(count==0)
break;
start=temp;
used[tempj]=1;
num++;
}
if(start==1)
{
if(num<min)
min=num;
}
}
}
printf("%d\n",min);
}
int main()
{
while(cin>>N>>T)
{
read();
solve();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator