codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)
题目链接:http://codeforces.com/contest/752/problem/C
题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个
路径走下去。
显然最后位置肯定要标记,然后怎么使得点最少呢。首先标记一下起点由于机器人走的是最短路一旦第i个点到
标记点的距离小于第i-1个点到标记点的距离是肯定不能这么走,于是这时就要标记一下上个点的位置,统计数
加1。
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int M = 2e5 + 10;
int a[M];
int main() {
string s;
int n;
cin >> n;
cin >> s;
int len = s.size();
int count = 0;
int x = 0 , y = 0 , stax = 0 , stay = 0;
int cp = 0;
for(int i = 0 ; i < n ; i++) {
if(s[i] == 'U') {
y++;
int gg = abs(y - stay) + abs(x - stax);
if(gg >= cp) {
cp = gg;
}
else {
count++;
stax = x;
stay = y - 1;
cp = 1;
}
}
if(s[i] == 'D') {
y--;
int gg = abs(y - stay) + abs(x - stax);
if(gg >= cp) {
cp = gg;
}
else {
count++;
stax = x;
stay = y + 1;
cp = 1;
}
}
if(s[i] == 'L') {
x--;
int gg = abs(y - stay) + abs(x - stax);
if(gg >= cp) {
cp = gg;
}
else {
count++;
stax = x + 1;
stay = y;
cp = 1;
}
}
if(s[i] == 'R') {
x++;
int gg = abs(y - stay) + abs(x - stax);
if(gg >= cp) {
cp = gg;
}
else {
count++;
stax = x - 1;
stay = y;
cp = 1;
}
}
}
cout << count + 1 << endl;
return 0;
}
codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)的更多相关文章
- Codeforces Round #389 Div.2 C. Santa Claus and Robot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 E. Santa Claus and Tangerines
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 A. Santa Claus and a Place in a Class
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!
A. Santa Claus and a Place in a Class 模拟题.(0:12) 题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述.给出n,m及k.求编号为k的桌子在 ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
随机推荐
- 【Spring源码解析】—— 委派模式的理解和使用
一.什么是委派模式 委派模式,是指什么呢?从字面含义理解,委派就是委托安排的意思,委派模式就是在做具体某件事情的过程中,交给其他人来做,这个事件就是在我的完整链路上的一部分,但是复杂度较高的情况下或者 ...
- python基础之条件控制
行与缩进 python使用缩进来表示代码块,不需要使用大括号 {} ,同一个代码块的语句必须包含相同的缩进空格数. 条件控制 #条件控制语法: if 条件: 代码块 elif 条件: 代码块 else ...
- 1关于如何用Navicat连接到xampp安装的mysql
打开xampp,打开config打开my.ini. 检索bind-address,后面的数字是你的IP地址 检索 port,后面的数字是端口号 打开Navicat新建连接,选中mysql 连接名随便起 ...
- ThreadPoolExecutor线程池的一个面试题
问题:现有一个线程池,参数corePoolSize = 5,maximumPoolSize = 10,BlockingQueue阻塞队列长度为5,此时有4个任务同时进来,问:线程池会创建几条线程? 如 ...
- win10 我的电脑下面的六个文件夹的隐藏
第一步 第二步 第三步 修改注册表,要隐藏那个文件夹,ThisPCPolicy 改为 "Hide" 修改我的文档的注册表值,使我的文档文件夹隐藏 <w ...
- mac下使用zerobrane调试cocos2dx的lua
环境:MacOSx 10.9.2, Lua 5.1.4, luaSocket 2.0.2, xcode5.0.2 所需文件 luasocket-2.0.2.zip,ZeroBraneStudioEdu ...
- 初识JavaScript和面向对象
1.javascript基本数据类型: number: 数值类型 string: 字符串类型 boolean: 布尔类型 null: 空类型 undefault:未定义类型 object: 基本数据类 ...
- SoapSerialization——手机号码归属地
public class MainActivity extends AppCompatActivity { private EditText etNumber; private TextView tv ...
- String关键字
关于String和new String()见我写的前一篇博客 String和new String()的区别 1.String的"+"运算 a.String str = " ...
- 从原理层面掌握@ModelAttribute的使用(使用篇)【一起学Spring MVC】
每篇一句 每个人都应该想清楚这个问题:你是祖师爷赏饭吃的,还是靠老天爷赏饭吃的 前言 上篇文章 描绘了@ModelAttribute的核心原理,这篇聚焦在场景使用上,演示@ModelAttribute ...