Radar Installation(利用数据有序化进行贪心选择)
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(利用数据有序化进行贪心选择)的更多相关文章
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
/* * URAL_1014.cpp * * Created on: 2013年10月11日 * Author: Administrator */ #include <iostream> ...
- Radar Installation(POJ 1328 区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68578 Accepted: 15 ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
- (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)
/* * UVA_10026.cpp * * Created on: 2013年10月10日 * Author: Administrator */ #include <iostream> ...
- 【贪心】「poj1328」Radar Installation
建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- 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 (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- PTA 学生成绩链表处理(C语言)
本题要求实现两个函数,一个将输入的学生成绩组织成单向链表:另一个将成绩低于某分数线的学生结点从链表中删除. 函数接口定义: struct stud_node *createlist(); struct ...
- postman请求(请求方式、请求url、请求参数、参数类型、请求头)
请求方式:get 请求地址: 请求参数:url与参数用?间隔,多个参数用&间隔 请求方式:post 请求地址: 请求参数: 请求参数格式:前面两种是key-value.第三种可以选择json/ ...
- php趣题小记
题目一: $a = 'abc'; $a++; echo $a; // abd 题目二: function myfun($a){ echo $a+10; } $a = 10; echo "my ...
- 框架里增加.env文件的作用
在实际开发中我们常常遇到这样的问题,就是开发地点不固定,这就造成了我们需要频繁的更改数据库配置,给开发工作造成了麻烦,.env环境文件的出现解决了这个麻烦,我们只需要在不同的工作地点配置好.env文件 ...
- 安装MySQL被提示缺少msvcr120.dll,msvcp120.dll或提示0xc00007b错误
踩坑经历: 我的电脑昨天重装了win10系统,在安装MySQL时被提示缺少msvcr120.dll,我去下载msvcr120.dll后放入System32中,又被提示缺少msvcp120.dll,然后 ...
- iframe刷新另一个iframe
如果是程序: Response.Write("<script language=javascript>"); Response.Write ...
- python复习基础题目
第一部分 必答题(每题2分) 简述列举了解的编程语言及语言间的区别? 编译型语言:一次性全部编译成二进制码,再去执行 解释性语言:编译一句,运行一句 python 解释型,简洁高效,容易上手 Java ...
- Codeforces 1304F2 Animal Observation (hard version) 代码(dp滑动窗口线段树区间更新优化)
https://codeforces.com/contest/1304/problem/F2 #include<bits/stdc++.h> using namespace std; ; ...
- 浅谈C#委托的用法-delegate[转]
一.委托的概念 委托和类一样是一种用户自定义类型,它存储的就是一系列具有相同签名和返回类型的方法的地址,调用委托的时候,它所包含的所有方法都会被执行. 借用百度上的一句话概括:委托是一个类,它定义了方 ...
- PHP目录操作(附封装好的目录操作函数文件)
目录函数库常用API $path='test'; var_dump(is_dir($path));//检测是否为目录 echo '<hr/>'; echo getcwd();//得到当前的 ...