UVALIVE 2519 Radar Installation 区间选点问题
2014-07-05 22:12
330 查看
#include <map> #include <set> #include <list> #include <cmath> #include<cctype> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; #define MAXN 1005 int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } int N,R; bool vis[MAXN]; struct node { double l,r; friend bool operator <(const node &a, const node &b) { if (a.r==b.r)return a.l<b.l; return a.r<b.r; } }src[MAXN]; int main() { //freopen("sample.txt","r",stdin); int kase=1; while (scanf("%d%d",&N,&R)!=EOF) { if (N==0 && R==0) break; bool found=false; int x,y; for (int i=0;i<N;i++) { scanf("%d%d",&x,&y); if (y>R) found=true; double t=sqrt((double)(R*R-y*y)); src[i].l=x-t; src[i].r=x+t; } printf("Case %d: ",kase++); if (found) printf("-1\n"); else { sort(src,src+N); memset(vis,false,sizeof(vis)); int ans=0; double tmp; for (int i=0;i<N;i++) { if (vis[i]) continue; ans++; int j=i+1; tmp=src[i].r; while (j<N){ if (!vis[j] && src[j].l<=tmp) vis[j]=true; j++; } } printf("%d\n",ans); } } return 0; }
相关文章推荐
- UVALive 2519 Radar Installation 雷达扫描 区间选点问题
- uvalive 2519 - Radar Installation(区间选点问题)
- UVALive - 2519 Radar Installation(区间选点问题)
- UVAlive 2519 Radar Installation (区间选点问题)
- UVAlive 2519 Radar Installation (区间选点问题)
- UVALive 2519 Radar Installation 雷达扫描 区间选点问题
- 初入算法篇(贪心)区间选点+uvalive2519
- UVALive 2326 Moving Tables(贪心+不相交区间问题)
- UVA 11134 Fabled Rooks(贪心法,区间与选点问题)
- uva 10148 - Advertisement(区间选点问题)
- uvalive 2326 - Moving Tables(区间覆盖问题)
- UVAlive 2326 Moving Tables(贪心 + 区间问题)
- uvalive 2326 - Moving Tables(区间覆盖问题)
- uvaLive 2387 - Gene Assembly 最大区间调度问题
- UVa 1615 Highway (贪心,区间选点问题)
- UVAlive 2326 Moving Tables(贪心 + 区间问题)
- uvaLive 3222 Joke with Turtles 带权区间调度、覆盖问题 等价转换+线性动归
- [J - Minimal Subarray Length UVALive - 6609] 区间问题
- UVA 10148 Advertisement (贪心 + 区间选点问题)
- Uva 11134 问题分解,贪心策略区间选点问题