翻出一年多前的代码看,发现以前的代码风格很糟糕

题意:给你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_贪心的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  3. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  4. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  6. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  7. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  8. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  9. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

随机推荐

  1. UESTC_秋实大哥与连锁快餐店 2015 UESTC Training for Graph Theory<Problem A>

    A - 秋实大哥与连锁快餐店 Time Limit: 9000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) S ...

  2. POJ3026(BFS + prim)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10554   Accepted: 3501 Descri ...

  3. Pros and Cons of T4 in Visual Studio 2008

    Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...

  4. hdu 3681 Prison Break(状态压缩+bfs)

    Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...

  5. UISearchBar 点击X 按钮收键盘

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;{ NSLog(@"textD ...

  6. VS2012+SQL2008+ODBC编程,第一篇博客,写的不好忘各位大神指点一二~

    近期写一个数据库的课程设计,用的是C++ MFC .最開始用的是ADO技术,可是苦于网上大部分的教程都是VC6.0的,对着教程敲了4,5遍还是执行不成功.我用的IDE是VS2012,毕竟VC6.0和V ...

  7. Android应用自动更新功能的实现!!!

    自动更新功能的实现原理,就是我们事先和后台协商好一个接口,我们在应用的主Activity里,去访问这个接口,如果需要更新,后台会返回一些数据(比如,提示语:最新版本的url等).然后我们给出提示框,用 ...

  8. transition的唧唧歪歪

    transition是css3新出的一个属性,大白话叫做过渡. 主要有下面这四个属性: transition-property.transition-duration.transition-timin ...

  9. php Debugging with Xdebug and Sublime Text 3(转)

    Debugging – we all do it a lot. Writing code perfectly the first time around is hard and only a few ...

  10. Spring 之 注解详解

    概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作.如使用 JPA 注释配置 ORM 映射时,我们就不需要指定 PO ...