poj 3069 贪心算法
来源:互联网 发布:苏沉船 王晶 知乎 编辑:程序博客网 时间:2024/06/05 04:36
题目链接:http://poj.org/problem?id=3069
一开始想了一种思路错了,最后发现就是从第一个点开始找到在范围内却又最远的点标记上,然后在从这个点找范围外最近的点,重复之前的操作就行了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define M 1009#define INF 0x3f3f3f3fint mark[M];int s[M];int main(){ int n,m; while(scanf("%d %d",&n,&m)==2) { int a; memset(mark,0,sizeof(mark)); if(n==-1 && m==-1) break; int max = -INF; for(int i = 0;i < m;i++) { scanf("%d",&s[i]); } int ans = 0; int i=0; sort(s,s+m); while(i<m) { int st = s[i]; while(i<m && s[i]<=st+n) i++; int p = s[i-1]; while(i<m && s[i]<=p+n) i++; ans++; } printf("%d\n",ans); } return 0;}
0 0
- poj 3069 贪心算法
- POJ 3069 Saruman's Army 贪心算法
- 贪心算法poj 3617,3069,3253
- POJ 1089 贪心算法
- poj 1017 贪心算法
- POJ-1328(贪心算法)
- POJ 1328 贪心算法
- POJ 2287贪心算法
- POJ 1700贪心算法
- POJ 1328 简单贪心算法
- POJ 3485 Highway(贪心算法)
- POJ 3069 Saruman's Army(贪心算法)
- poj 3069(贪心算法之字典序排序)
- poj 3069(纯贪心)
- poj 3069 贪心
- poj 3069贪心~
- POJ 3069 贪心
- POJ 3617 3069 贪心
- 链表操作
- HDU 4336 Card Collector 概率dp 状态压缩| 容斥原理
- cantos安装redis
- UnsatisfiedLinkError Native method not found:
- (十五) YII2 将参数传递到layouts/main.php中
- poj 3069 贪心算法
- uva 11552(dp)
- (十六)yii2 视图中渲染到另一个视图中
- 简单链表操作
- Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL
- 关于苹果《Genius Bar 天才吧》预约流程
- java-集合类(二)-迭代器-Iterator-Collections类自然排序
- linux系统-进程管理-基本概念和命令
- objective_c 第九章课后练习题答案