UVA 2519 Radar Installtion

思路:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cstdlib>
 7 using namespace std;
 8 struct tt{
 9     double l,r;//左右指针
10 }p[1010];//线段序列
11 /*
12 第i个岛屿被雷达覆盖的水平线段为[p[i].l,p[i].r]
13 */
14
15 int n,d;//岛屿数,雷达覆盖距离
16
17 void input()
18 {
19     double x,y,h;
20     for(int i=0;i<n;i++)
21     {
22         scanf("%lf%lf",&x,&y);
23         if(y>d)//岛屿离岸边距离大于雷达距离
24         {
25             d=-1;
26             return;
27         }
28         h=sqrt(d*d-y*y);//计算岛屿线段半长
29         p[i].l=x-h;//设置左右指针
30         p[i].r=x+h;
31     }
32 }
33 //以右端点为第一,左端点为第二关键字,递增排序
34 bool cmp(const tt &a,const tt &b)
35 {
36     if(a.r<b.r)
37     return true;
38     if(a.r==b.r&&(a.l<b.l))
39     return true;
40     return false;
41 }
42
43 void work()
44 {
45     if(d==-1)
46     {
47         printf("-1\n");
48         return;
49     }
50     sort(p,p+n,cmp);
51     int ans=0;
52     double last=-100000000;//安装雷达的位置
53     for(int i=0;i<n;i++)
54     {
55         if(p[i].l<=last)//此位置已经有雷达
56             continue;
57         ans++;
58         last=p[i].r;//没有雷达就在右边放一个
59     }
60     printf("%d\n",ans);
61 }
62
63 int main()
64 {
65     int cnt=0;
66     while(scanf("%d%d",&n,&d),n+d)
67     {
68         printf("Case %d: ",++cnt);
69         input();
70         work();
71     }
72     return 0;
73 }

原文地址:https://www.cnblogs.com/fudanxi/p/10447131.html

时间: 2024-10-13 00:29:49

UVA 2519 Radar Installtion的相关文章

UVALive - 2519 Radar Installation 解题心得

原题: Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distanc

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

POJ 1328 Radar Installation

http://poj.org/problem?id=1328 //第一次:从左边第一个未被覆盖的island开始 -->>失败 因为还有y坐标这一因素 不能保证贪心//第二次:找两个点 确定一个圆 ----->>>其实早就应该发现错误 漏洞百出 不具有普遍性//从左边第一个未覆盖的点作为基点 找到第一个 y坐标>=的点(如果没有找到) 做这两个点的公共圆//如果不能做这两个点的公共圆 或者 没有y>=的点 那么做这个圆的右极限圆//更新覆盖的点//蠢-->&

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica