其实我还是觉得是贪心。
给出N段挤牛奶的时间,球出最长至少一人挤奶时间和最长无人挤奶时间。
之前判断哪里出了点问题一直卡在test 7 ,看了下nocow,..>_<
哎,感觉还没回来,还要恢复啊,还要准备新苗计划的申报== ,论文一大堆。还要保证正常作息时间,稍微一熬就12点多。
usaco灭了,zoj做到300题就退役吧。是不是有点灰心了- -囧
/*
ID: zisu_123
LANG: C
TASK: milk2
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct milk2{
int start,end;
}milk2;
int cmp( const void *a , const void *b )
{
struct milk2 *c = (milk2 *)a;
struct milk2 *d = (milk2 *)b;
if(c->start != d->start) return c->start - d->start ;
else return d->end - c->end;
}
main()
{
FILE *fin = fopen ("milk2.in", "r");
FILE *fout = fopen ("milk2.out", "w");
int N;
int i,t,t1,t2;
milk2 milk[5005],dis1;
fscanf(fin,"%d",&N);
for(i=0;i<N;i++)
fscanf(fin,"%d%d",&milk[i].start,&milk[i].end);
qsort(milk,N,sizeof(milk[0]),cmp);
dis1=milk[0];
t=0;
t1=0;
t2=0;
for(i=1;i<N;i++)
{
if(dis1.end<milk[i].start)
{
t=milk[i].start-dis1.end;
if(t>t1)
t1=t;
t=dis1.end-dis1.start;
if(t>t2)
t2=t;
dis1=milk[i];
}
else
{
if(milk[i].end >dis1.end)
dis1.end =milk[i].end;
}
}
t=dis1.end -dis1.start ;
if(t>t2)
t2=t;
fprintf(fout,"%d %d\n",t2,t1);
exit (0);
}