您的位置:首页 > 其它

高速公路(Highway,ACM/ICPC SEERC 2005,UVa1615)

2016-07-17 15:45 447 查看


I think:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct port
{
long long x,y,l,r;
};
int cmp(const void *a,const void *b)
{
struct port *x=(struct port *)a;
struct port *y=(struct port *)b;
return x->l - y->l;

}
struct port p[1000000];
int main(void)
{
long long wayLen,d,i,v,sum;
long long c,tem;
while(scanf("%lld%lld%lld",&wayLen,&d,&v)!=EOF)
{
sum=1;
for(i=0; i<v; i++)
{
scanf("%lld%lld",&p[i].x,&p[i].y);
c=sqrt(d*d-p[i].y*p[i].y);
p[i].r=c+p[i].x;
p[i].l=p[i].x-c;
}
qsort(p,v,sizeof(p[0]),cmp);
tem=p[0].r;
for(i=1; i<v; i++)
{
if(p[i].l<=tem)
continue;
else
{
tem=p[i].r;
++sum;
}
}
printf("%lld\n",sum);
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: