【贪心】POJ - 3069 Saruman's Army
题意
给n个点,从中选择若干个标记,在距离标记为r的范围内包含其他的点,最少需要几个标记,才能将所有的点包含在内
思路
贪心。先排序,从最左边的点开始找到此半径内最大的点,则此点就是第一个标记,以此类推
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 using namespace std; 7 const int maxn = 20000 + 5; 8 int n, m, T; 9 int s[maxn]; 10 int main() 11 { 12 13 while(scanf("%d %d", &m, &n) == 2 && m != -1) { 14 for(int i = 0; i < n; i++) { 15 scanf("%d", &s[i]); 16 } 17 sort(s, s+n); 18 int ans = 0; 19 int i = 0; 20 while(i < n) { 21 int t = s[i++] + m; 22 while(i < n && s[i] <= t) { 23 i++; 24 } 25 t = s[i-1] + m; 26 while(i < n && s[i] <= t) { 27 i++; 28 } 29 ans++; 30 } 31 printf("%d\n", ans); 32 } 33 return 0; 34 }
转载于:https://www.cnblogs.com/kikii233/p/6357517.html
【贪心】POJ - 3069 Saruman's Army相关推荐
- 【题解】POJ 3069 Saruman's Army(贪心)
POJ 3069 Saruman's Army 原题 https://vjudge.net/problem/POJ-3069 白种人萨鲁曼必须带领他的军队沿着从艾辛格到圣盔谷的直线前进.为了跟踪他的部 ...
- POJ 3069 Saruman's Army(萨鲁曼军)
POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Saruman ...
- POJ 3069 Saruman's Army(贪心)
题目链接:http://poj.org/problem?id=3069 Description Saruman the White must lead his army along a straigh ...
- POJ - 3069 Saruman's Army 萨鲁曼的大军 贪心 重庆一中高2018级竞赛班第三次测试 2016.7.24 Problem 2
[问题描述] 萨鲁曼的大军正行进在一条笔直的道路上,由于是在夜晚行军,路上的石头严重地影响了行军速度.于是萨鲁曼决定预先在道路上安装一些路灯,以便士兵们能清楚地看到所有石头. 萨鲁曼给出n块石头的位置 ...
- POJ3069 Saruman's Army【贪心】
问题链接:POJ3069 Saruman's Army. 题意简述:直线上有N个点.点i的距离是Xi.从这N个点中选取若干点加上标记.对于每个点,与其距离为R的范围内必有做标记的点(包括自身).求至少 ...
- 贪心:Fence Repair、Saruman's Army
Fence Repair Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- 【ACM】POJ 3069
[问题描述] Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To k ...
- Saruman's Army
传送门 题目 Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To k ...
- Saruman's Army (POJ3069)
Saruman's Army 萨鲁曼的大军正行进在一条笔直的道路上,由于是在夜晚行军,路上的石头严重地影响了行军速度.于是萨鲁曼决定预先在道路上安装一些路灯,以便士兵们能清楚地看到所有石头. 萨鲁曼给 ...
最新文章
- 解决开机自检D盘问题
- 【JQuery】将Json Object序列化成URL的QueryString
- 4.day11_包和权限修饰符-1
- 在U盘上运行Win8!使用 Windows To Go 制作便携的 Win8 U盘/移动硬盘教程 (视频)
- Python的第三方库pandas
- ceph 代码分析 读_五大常见存储系统PK | Ceph、GlusterFS、MooseFS、HDFS、DRBD
- emui内核支持kvm吗_EMUI和MIUI为什么不基于安卓linux内核不使用虚拟机直接用c++开发一些更流畅系统自带软件呢?...
- ARM来中关村“卖艺”,地平线机器人科技拜码头
- Daimayuan Online Judge 上帝的集合
- matlab2017b和2018a,Matlab 2018a 比2017b有哪些改进?
- 个人博客项目(2) --- 用户登录
- 校招 | 网易21届互联网校招补录来啦!
- DO、PO、VO、DTO、BO、POJO概念
- 输入框上的Magnifier
- 6月25日科技资讯 |微信解封快手链接;AWS证实宕机;微软公司内部疑禁用Slack
- 当心Azure跨区域数据传输产生额外费用
- InverseCSG: Automatic Conversion of 3D Models to CSG Trees
- [渝粤教育] 中国地质大学 政府与事业单位会计 复习题
- 用户权限验证的两种方法
- JAVA单元测试——常用注解(案例源码分析)