poj3069 Saruman's Army(贪心)
https://vjudge.net/problem/POJ-3069
弄清楚一点,第一个stone的位置,考虑左右两边都要覆盖R,所以一般情况下不会在左边第一个(除非前两个相距>R)。
一开始二层循环外层写的i=1,这样对于数据诸如1 1 1=>0,而其实结果是1.
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int R, n, a[];
int main()
{
while(cin >> R >> n){
if(R == -&&n == -) break;
for(int i = ; i < n; i++){
cin >> a[i];
}
sort(a, a+n);
int flag=;
int st = , ans=;//st表示第一个未被覆盖的点
for(int i = ; i < n;){//一开始这里写的i=0,WA了
while(i < n&&a[i]-a[st]<=R){
i++;
}
int t = i-;//此处放一个
ans++;
while(i < n&&a[i]-a[t]<=R){
i++;
}
st = i;
}
cout << ans << endl;
}
return ;
}
poj3069 Saruman's Army(贪心)的更多相关文章
- POJ3069 Saruman's Army【贪心】
Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep tra ...
- POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心
带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...
- poj3069 Saruman's Army
http://poj.org/problem?id=3069 Saruman the White must lead his army along a straight path from Iseng ...
- POJ 3069 Saruman's Army(贪心)
Saruman's Army Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 3069 Saruman's Army 贪心模拟
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18794 Accepted: 9222 D ...
- B - B Saruman's Army(贪心)
在一条直线上,有n个点.从这n个点中选择若干个,给他们加上标记.对于每一个点,其距离为R以内的区域里必须有一个被标记的点.问至少要有多少点被加上标记 Saruman the White must le ...
- poj 3069 Saruman's Army 贪心 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=3069 题解 题目可以考虑贪心 尽可能的根据题意选择靠右边的点 注意 开始无标记点 寻找左侧第一个没覆盖的点 再来推算既可能靠右的标记点为一 ...
- Saruman's Army(贪心)
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep tra ...
- Saruman's Army(POJ3069)
Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. ...
随机推荐
- spring、springmvc、springboot、springcloud
Spring 最初利用“工厂模式”( DI )和“代理模式”( AOP )解耦应用组件.大家觉得挺好用,于是按照这种模式搞了一个 MVC 框架(一些用 Spring 解耦的组件),用开发 web 应用 ...
- sed 简单修改配置文件ip地址
sed -i 's/old ip/new ip/g' file.txt
- Codeforces 844F Anti-Palindromize 最小费用流
Anti-Palindromize 想到网络流就差不多了, 拆拆点, 建建边. #include<bits/stdc++.h> #define LL long long #define f ...
- 查看当前的app运行的是哪个Activity
1.确认手机连接了adb-->检查方式:adb devices 2.手机运行任意app,随意进入一个页面 3.此时cmd运行:adb shell "dumpsys window | g ...
- Codeforces 830C Bamboo Partition 其他
原文链接https://www.cnblogs.com/zhouzhendong/p/CF830C.html 题解 把问题转化成求最大的 $d$ ,满足$$\sum_{1\leq i \leq n}( ...
- day11 装饰器---函数的使用方法
这个是一个难点,以后面试会经常出现的,要搞懂! 装饰器升级版,进阶内容1: def outer(flag): def wrapper(func): def inner(*args,**kwargs): ...
- html-选择对象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python2.7安装和uwsgi
python2.7安装和uwsgi tar zxf Python-2.7.13xxxx# 这里,必须用–enable-shared,生成动态库,否则会遇到wsgi不能编译的问题. Bonus: mul ...
- SVM:利用SVM算法实现手写图片识别(数据集50000张图片)—Jason niu
import mnist_loader # Third-party libraries from sklearn import svm def svm_baseline(): training_dat ...
- iframe实现伪ajax
iframe实现伪ajax 数据提交的两种方式: Form Ajax Ajax提交数据的方法: JS实现 Jquery “伪”Ajax "伪"Ajax: iframe+from实现 ...