poj 1328
来源:互联网 发布:程序员薪资城市排行榜 编辑:程序博客网 时间:2024/06/15 22:52
题意:
有一条直线,在直线的一端有一些岛屿。问你在直线上放多少雷达能使所有岛屿被覆盖。
如果岛屿能被覆盖,那么他们在直线上有两个极限值,刚刚好在这两个点上放雷达能够覆盖对应雷达。
那么我们就可以贪心了。依据每个雷达能够接受的最大x排序,从左端开始选取最大x,直到不能满足条件,更新。
坑点,雷达半径可为负
#include<cstdio>#include<algorithm>#include<cmath>#include<iostream>using namespace std;const int maxn = 1000 + 5;struct node{ double x, y; node() { } node(double a, double b): x(a), y(b){} bool operator<(const node &a) const { return y < a.y; }}island[maxn];int main(){ int n, k; int kase = 0; while(scanf("%d%d", &n, &k) == 2 && (n || k)) { if(kase) printf("\n"); int cnt = 0; bool flag = true; for(int i = 0; i < n; i++) { double t1, t2; cin>>t1>>t2; double temp = sqrt(k * k - t2 * t2); if(k * k - t2 * t2 < 0 || k < 0) flag = false; island[i] = node(t1 - temp, t1 + temp); } sort(island, island + n); if(flag) { cnt++; double pos = island[0].y; for(int i = 1; i < n; i++) { if(island[i].x > pos) { cnt++; pos = island[i].y; } } } printf("Case %d: %d", kase++ + 1, flag == true ? cnt: -1); } return 0;}
阅读全文
0 0
- poj 1083 & poj 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ--1328
- poj-1328
- POJ 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ 1328
- poj 1328
- Python基础知识之生成器
- android 中的toast short 和long的区别
- 微信小程序
- 热点讨论:IT人,40岁以后能干什么?
- 一些感想
- poj 1328
- [技巧分享-widow10系统]修改window系统桌面图片
- 如何在Centos下设置Vim的永久显示行号功能?
- jstack日志深入理解
- Java中创建对象的5种方式
- 语言实践2-驱动学习(2)驱动程序框架
- 去除WinRAR的广告
- 大数据正式20
- 经典算法---堆排序(Heapsort)