BJTU 1623 Problem C. Course Planning

http://acm.bjtu.edu.cn/problem/detail?pid=1623

贪心,关键点是以课程的结束时间为标准排序

View Code
#include <stdio.h>
#include <stdlib.h>
struct node
{
__int64 x,y;
}kk[110000];
int cmp(const void*a,const void*b)
{
struct node*c=(struct node*)a;
struct node*d=(struct node*)b;
if(d->y==c->y)
return d->x-c->x;
return d->y-c->y;
}
int main()
{
int t,n;
int nCase;
int i,f;
nCase=1;
scanf("%d",&t);
while(t--)
{
f=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%I64d%I64d",&kk[i].x,&kk[i].y);
qsort(kk,n,sizeof(struct node),cmp);
for(i=0;i<n-1;i++)
if((kk[i].y-(kk[i].y-kk[i].x)/2-1)<=(kk[i+1].y-(kk[i+1].y-kk[i+1].x)/2-1))
{
f=1;
break;
}
if(f)
printf("Case #%d: No\n",nCase++);
else
printf("Case #%d: Yes\n",nCase++);
}
return 0;
}


 

原文地址:https://www.cnblogs.com/xiaohongmao/p/2431886.html