生活随笔
收集整理的這篇文章主要介紹了
uva 1615——Highway
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意: 給定平面上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);}
}
總結
以上是生活随笔為你收集整理的uva 1615——Highway的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。