English appre:

an infinite straight line:一条无限长的直线

on the coasting:在海岸线上

Cartesian coordinate system,

题目地址:http://poj.org/problem?id=1328

我的代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct dao
{
double x,y;
}da[10000];
bool cmp(dao a,dao b)
{
return (a.y<b.y)||(a.y==b.y && a.x>b.x);
} int main()
{
int n,d;
double x1,y1;
int k=0;
while(~scanf("%d%d",&n,&d)&&(n||d))
{
int ans=1;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&x1,&y1);
da[i].x=x1-sqrt((double)d*(double)d-(double)y1*y1);
da[i].y=x1+sqrt((double)d*(double)d-(double)y1*y1);
if((d-y1)<0||d<=0) ans=-1;
} if(ans==-1)
{
printf("Case %d: -1\n",++k);
continue;
}
else
{
sort(da,da+n,cmp);
double t1=da[0].y;
for(int i=1;i<n;i++)
if(da[i].x>t1)//要是用=号,有些数据不可通过。
{
ans++;
t1=da[i].y;//更新右范围
}
printf("Case %d: %d\n",++k, ans);
}
}
}

  

Radar Installation(利用数据有序化进行贪心选择)的更多相关文章

  1. (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)

    /* * URAL_1014.cpp * * Created on: 2013年10月11日 * Author: Administrator */ #include <iostream> ...

  2. Radar Installation(POJ 1328 区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68578   Accepted: 15 ...

  3. POJ 1328 Radar Installation(很新颖的贪心,区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 106491   Accepted: 2 ...

  4. (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)

    /* * UVA_10026.cpp * * Created on: 2013年10月10日 * Author: Administrator */ #include <iostream> ...

  5. 【贪心】「poj1328」Radar Installation

    建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...

  6. 贪心 POJ 1328 Radar Installation

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

  7. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  8. poj 1328 Radar Installation(贪心)

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

  9. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. 【剑指Offer】62、序列化二叉树

    题目描述 请实现两个函数,分别用来序列化和反序列化二叉树 二叉树的序列化是指:把一棵二叉树按照某种遍历方式的结果以某种格式保存为字符串,从而使得内存中建立起来的二叉树可以持久保存.序列化可以基于先序. ...

  2. 吴裕雄--天生自然HADOOP操作实验学习笔记:分布式资源调度系统yarn的安装

    实验目的 复习配置hadoop初始化环境 复习配置hdfs的配置文件 学会配置hadoop的配置文件 了解yarn的原理 实验原理 1.yarn是什么 前面安装好了hdfs文件系统,我们可以根据需求进 ...

  3. 一个margin就可以让块状元素响应居中,很实用

    之前总结过水平居中的很多方法,但今天在<css世界>这本书里看到margin的一个特性,一行代码就搞定很实用,分享一下 margin: auto能在块级元素设定宽高之后自动填充剩余宽高.m ...

  4. Android ListView的批量处理(多选/反选/删除)

    在Android开发中经常遇到使用ListView的情况,有时候需要的不仅仅是列表显示,还有长按列表进行多选,并且批量删除的情况,在这里记录一下自己的所学. 先上效果图: 几个需要用到的核心方法: / ...

  5. the simmon effect(in psychology) :build the function of subject_information(modify the experiment programme),before we begin the experiment

    #the real experiment for simon effect #load the library which is our need import pygame import sys i ...

  6. OCM 12c | OCM 12c Update | OCM 11g (Retiring Dec 31, 2019) | OCM 11g考试延期至2020.04.30

     OCM 全球考试安排时间表 View A Worldwide OCM Schedule Oracle Database 12c Certified Master Exam (OCM) OCM 12c ...

  7. 查询避免Unknown column ‘xxx’ in ‘where clause

    问题: 单从字面理解,我们很容易得出列名称不存在的结论, 但是,很多时候并不是列名出错造成的,而是由于拼凑sql语句时对字符类型数据没有用引号引起来造成的. 例子: 例如:  String sql=& ...

  8. react-父子子孙组件嵌套-context

    方案一 import React from 'react' import ReactTypes from 'prop-types' /* // 最外层的父组件 export default class ...

  9. php redis使用

    访问连接 远程访问 //实例化 $redis=new Redis(); try{ $redis->connect('47.98.55.11','6379'); $redis->auth(' ...

  10. Visual Studio 问题汇总

    VS2019 16.3.6   1   JSON 文件没有进行格式化验证 开发时运行正常,部署在IIS中有错误提示. 2  .NET Core 3.0 没有提供中文包 所有注释都是英文的.