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

题意:给你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. Java Socket 简单梳理

    Sockets let you send raw streams of bytes back and forth between two computers, giving you fairly lo ...

  2. github page使用

    github page介绍: https://help.github.com/categories/20/articles 使用GitHub Pages建立博客 与GitHub建立好链接之后,就可以方 ...

  3. PV与并发之间换算的算法 换算公式

  4. 关于找不到stdafx.h头文件问题

    代码: #include "stdafx.h" #include "stdlib.h" char* getcharBuffer() { return " ...

  5. 导入时如何定制spring-boot依赖项的版本

    spring-boot通过maven的依赖管理为我们写好了很多依赖项及其版本,我们可拿来使用.spring-boot文档介绍了两种使用方法,一是继承,二是导入. 通过<parent>继承: ...

  6. Windows多线程同步系列之一-----互斥对象

    多线程同步之互斥对象 作者:vpoet mail:vpoet_sir@163.com   对卖票问题进行线程间同步,本文将在上文的基础上,使用互斥对象对线程进行同步. 首先看看windows API ...

  7. MongoDB C Driver and APIinstances linux MongoDB安装配置

    <一,linux平台MongoDB安装配置>在这我们使用的Centos6 yum部署的,你想搞编译,自个干!

  8. HDU-1016-素数环

    /* 将1-n个数放在环中,保证相邻的两个数的和是素数 第一个数字永远是1 就这两个约束条件 第一个难点是计算素数: 参考文献: http://c.biancheng.net/cpp/html/254 ...

  9. debian msyql 5.1 卸载与安装

    卸载:apt-get autoremove --purge mysql-server-5.1 卸载服务端 apt-get remove mysql-common #一定要卸载(包含配置文件) dpkg ...

  10. svo的一些博客解析

    记录一边学习 白巧克力: svo代码笔记 http://blog.csdn.net/heyijia0327/article/details/51083398 卢彦斌:svo原理解析 东北大学孙志明:s ...