poj 3069贪心
来源:互联网 发布:软件开发高级工程师 编辑:程序博客网 时间:2024/05/16 18:47
题目的大体意思就是坐标上的每一个点有一个半径为r的搜索范围,如果不在这个半径范围内的话就需要加一个仪器判断如果需要最少的仪器一个贪心的思想吧,
这个题那时候做训练赛的时候没做出来,后来补出来的,不得不承认,脑子思考不行,还要继续努力,下面附上代码,
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn = 1001;int n, r;int x[maxn];void work(){ sort(x, x + n); int i = 0, ans = 0; while(i < n) { int s = x[i++]; while(i < n && x[i] <= s + r) i++; int p = x[i - 1]; while(i < n && x[i] <= p + r) i++; ans++; } printf("%d\n", ans);}int main(){ while(scanf("%d%d", &r, &n) && !(r == -1 && n == -1)) { for(int i = 0; i < n; i++) scanf("%d", &x[i]); work(); } return 0;}
阅读全文
1 0
- poj 3069(纯贪心)
- poj 3069 贪心
- poj 3069 贪心算法
- poj 3069贪心~
- POJ 3069 贪心
- POJ 3617 3069 贪心
- poj 3069贪心
- poj 3069 贪心+区间问题
- POJ 3069 简单的贪心
- poj 3069 Saruman's Army 贪心
- poj 3069Saruman's Army 贪心
- poj 3069 Saruman's Army(贪心)
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 : Saruman\'s Army - 贪心
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 - Saruman's Army(贪心)
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 Saruman's Army(贪心)
- SpringMVC——对Ajax的处理(包含 JSON 类型)
- 2. ATF(ARM Trusted firmware)启动---bl1
- LoadRunner Web应用样例程序订票过程脚本
- 基于NoSQL内存数据库的Linux性能优化
- 从0到1构建大数据生态系列1:数据蛮荒中的拓荒之举
- poj 3069贪心
- (C#基础) byte[] 之初始化, 赋值,转换。
- nor flash启动与nand flash启动的区别
- JAVA多线程学习(详细总结)
- 设想假设1具体代码
- hdu 5901 Count primes (大素数模板)
- springBoot配置日志文件
- IOS中忽略警告的三种方法
- 结构体内存对齐