POJ 1328 Radar Installation 贪心(区间选点)
来源:互联网 发布:c语言函数声明的标准 编辑:程序博客网 时间:2024/06/08 18:28
区间选点问题,坑点 一个是double类型,2是y > d|| d < 0要考虑到,3是要按照左端点进行升序排序,4是算法核心内容,如果选取的cou作为雷达位置,那么从下一个区间开始选点,如果下一个区间的右端点比小于等于cou,那么让cou = 这个区间的右端点,如果下一个区间的左端点大于cou,那么再重新安装一个雷达,让雷达安放在这个区间的右端点上。
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <math.h>using namespace std;struct node{ double u; double v;}a[1123];bool cmp(node a, node b){ return a.u < b.u;}int main(){ int n, d; int i; double x, y; int count = 1; while(cin >> n >> d){ if(n == 0 && d == 0) break; int flag = false; for(i = 0;i < n;i++){ cin >> x >> y; if(y > d || d < 0){ flag = true; } a[i].u = x-sqrt(d*d - y*y); a[i].v = x+sqrt(d*d - y*y); } if(!flag){ int cnt; double cou; sort(a,a+n,cmp); cnt = 1; cou = a[0].v; for(i = 1;i < n;i++){ if(a[i].v <= cou){ cou = a[i].v; }else if(a[i].u > cou){ cnt++; cou = a[i].v; } } printf("Case %d: %d\n", count, cnt); }else { printf("Case %d: -1\n", count); } count++; } return 0;}
0 0
- POJ 1328 Radar Installation 贪心区间选点
- poj-1328 Radar Installation(贪心+区间选点)
- [ACM] POJ 1328 Radar Installation (贪心,区间选点问题)
- POJ - 1328 Radar Installation (贪心,区间选点问题)
- POJ 1328 Radar Installation(贪心+区间选点问题)
- POJ 1328 Radar Installation 贪心(区间选点)
- POJ 1328 Radar Installation (贪心,区间选点问题)
- (贪心,区间选点问题) Radar Installation POJ 1328
- POJ-Radar Installation-贪心-区间选点
- poj 1328 Radar Installation 【贪心】【区间选点问题】
- Radar Installation(贪心。 区间选点)
- POJ 1328 Radar Installation(区间贪心)
- [POJ 1328] Radar Installation (区间贪心)
- Radar Installation(区间选点)
- UVa 1193 / POJ 1328 / Beijing 2002 Radar Installation (贪心&区间选点)
- POJ 1328 Radar Installation(贪心——最少区间选点覆盖)
- POJ1328 Radar Installation 【贪心·区间选点】
- POJ1328 Radar Installation 【贪心·区间选点】
- 欢迎使用CSDN-markdown编辑器
- 【Codeforces Round 363 (Div 2) E】【概率DP 期望DP 逆推等价法】LRU Cache替换LRU原则超多步数后每个数据在Cache中的概率
- .Net AOP (四)EnterpriseLibary 实现方法
- centos7 python升级
- odoo根据模型生成security配置信息
- POJ 1328 Radar Installation 贪心(区间选点)
- JavaSE学习笔记之-----常用类
- Leetcode常用五大算法思想
- NYOJ 102 次方求模(快速求幂)
- 常用代码片段整理
- byteConvertInputStream
- Spark的worker运行分析
- unity调用java
- xcopy拷贝目录并排除特定文件