poj 1328 Radar Installation_贪心
翻出一年多前的代码看,发现以前的代码风格很糟糕
题意:给你n个点 m为圆的半径,问需要多少个圆能把全部点圈到
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct ss{
double x,y;
}a[1005];
int cmp(ss x,ss y)
{
if(x.x==y.x)return x.y<y.y;
else return x.x<y.x;
}
int main()
{
int n,i,sum,k,flag;
double x,y,m;
double tt,ww;
k=0;
while (cin>>n>>m)
{
if(n==0&&m==0.0)break;
k++;
flag=1;
sum=0;
if(m<0)flag=0;
for (i=0;i<n;i++)
{
cin>>x>>y;
if(y>m)flag=0;
if(y<0)flag=0;
tt=sqrt(m*m-y*y);
a[i].x=x*1.0-tt;
a[i].y=x*1.0+tt;
}
if(flag==0)
{cout<<"Case "<<k<<": "<<"-1"<<endl;continue;}
sort(a,a+n,cmp);
sum=1;
ww=a[0].y;
for (i=1;i<n;i++)
{
if(a[i].x>ww){
sum++;
ww=a[i].y;
}
else if(a[i].y<ww){
ww=a[i].y;
}
}
cout<<"Case "<<k<<": "<<sum<<endl;
}
return 0;
}
poj 1328 Radar Installation_贪心的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- POJ 1328 Radar Installation 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
随机推荐
- SVD学习
前言: 上一次写了关于PCA与LDA的文章,PCA的实现一般有两种,一种是用特征值分解去实现的,一种是用奇异值分解去实现的.在上篇文章中便是基于特征值分解的一种解释.特征值和奇异值在大部分人的印象中, ...
- css案例学习之用thead、tbody、tfoot实现漂亮的table布局
首先说说thead.tbody.tfoot <thead> <tbody> <tfoot> 无论前后顺序如何改变, <thead> 内的元素总是在表的最 ...
- jQuery UI 之 EasyUI 快速入门
jQuery EasyUI 基础 转载自(http://www.shouce.ren/api/view/a/3350) jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用户界面 ...
- Difference Between Mod_Python & Mod_Wsgi | eHow
Difference Between Mod_Python & Mod_Wsgi | eHow x YES NO Why not? Thanks for he ...
- Capture the Flag(模拟)
Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer se ...
- Can you solve this equation?(二分)
Can you solve this equation? Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Ja ...
- iOS 苹果app提交 ITC.apps.validation.prerelease_build_missing
提示这信息,由于没有选择包文件, 在提交页面以下bulid的区域, 加入你的app就可以 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWxpbmNleG ...
- C#中如何只保留小数点后面两位?
string.format("%.4f",1/3) 1.Math.Round(0.333333,2);//按照四舍五入的国际标准2. double dbdata=0.335333; ...
- POJ2241——The Tower of Babylon
The Tower of Babylon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2207 Accepted: 1 ...
- ASP.NET属性之AssociatedControlID
AssociatedControlID 是用在Asp.Net 中的 Label 控件上.给label控件关联一个ASP.NET的控件,在点击 这个 LABEL的时候,所关联的ASP.NET控件会获得焦 ...