uva 1615——Highway

来源:互联网 发布:图像处理区域填充算法 编辑:程序博客网 时间:2024/06/14 05:17

题意: 给定平面上n个点,和一个值D,要求在x轴上选出尽量少的点,使得对给定的点,都有一个点离他的欧几里德距离步超过D。


思路:区间覆盖问题。以平面上的点为圆心,以D为半径,求出来一个与x周相交的左右区间,那么只要多个圆都相交的那个区间ans就不用++;


code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <sstream>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=0x3fffffff;const int inf=-INF;const int N=100005;const int M=2005;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define cpy(x,a) memcpy(x,a,sizeof(a))#define fr(i,s,n) for (int i=s;i<=n;i++)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt  rt<<1#define rrt  rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);struct node{    int x,y;}v[N];int main(){    int n,l,d;;    while (~scanf("%d %d",&l,&d))    {        scanf("%d",&n);        int len=0;        fr(i,0,n-1)        {            int tx,ty;            scanf("%d %d",&tx,&ty);            int s=tx-sqrt(d*d-ty*ty);s=max(s,0);            int t=tx+sqrt(d*d-ty*ty);t=min(t,l);            v[i].x=s;v[i].y=t;        }        int s=1,t=v[0].y;        fr(i,1,n-1)        if (v[i].x>t)        {            s++;            t=v[i].y;        }        printf("%d\n",s);    }}



0 0