POJ 1328 Rader Installation
来源:互联网 发布:java十个数输出最小值 编辑:程序博客网 时间:2024/06/05 05:32
区间选点问题,贪心解决。
现将区间排序,排序的方法是按区间的右端排序。
每次取区间的右端,如果下一组区间包含取到的区间右端,判断下一组,否则取区间右端。
有一次wa,是因为判断是否为-1的值在循环之后没有置0.
#include <iostream>#include <algorithm>#include <cmath>struct extent { double l, r; }line[1100];bool cmp(extent a, extent b) { return a.r < b.r;}int main(int argc, char *argv[]) { int n, d, cnt_case = 0, ok; while(std::cin >> n >> d) { ok = 1; if(n == 0 && d == 0) { break; } double x, y; for(int i = 0; i < n; i++) { std::cin >> x >> y; double temp = double(d * d) - y * y; if(temp < 0 || d < 0) { ok = 0; } else { line[i].l = x - sqrt(temp); line[i].r = x + sqrt(temp); } } if(!ok) { cnt_case ++; std::cout << "Case " << cnt_case << ": -1"<< std::endl; } else { std::sort(line, line + n, cmp); int ans = 1; double temp = line[0].r; for(int i = 1; i < n; i++) { if(temp < line[i].l) { ans++; temp = line[i].r; } } cnt_case ++; std::cout << "Case " << cnt_case << ": " << ans << std::endl; } } return 0;}
阅读全文
0 0
- poj 1328 rader installation
- POJ 1328 Rader Installation
- Rader Installation(POJ_1328)
- POJ 1328 "Radar Installation"
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- 1328 poj Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- eclipse3.7 安装activiti及遇到的错误
- 查看eclipse的工作空间和tomcat的发布目录
- Python次位面——下载文件
- 1.空间数据的采集与组织
- 解决session跨域读取
- POJ 1328 Rader Installation
- java SSL加密通信
- jquery插件多文件文件上传
- Github使用1-入门
- Secondary NameNode的作用
- Java I/O流总结与巩固
- ~搭建JEESZ分布式架构6--ZooKeeper 集群的安装
- leetcode_96. Unique Binary Search Trees
- 利用DPCM&Huffman编码实现数据压缩_C语言实现