题目链接: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(思维题)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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的桌子在 ...

  8. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  9. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  10. 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 ...

随机推荐

  1. Python-默背单词

    ​ 数据库单词: 默认单词 单词说明 innodb 事务,主键,外键,tree,表行锁 myisam 主要以插入读取和插入操作 memory 所有数据保存在内存中 ACID 原子性,一致性,隔离性,持 ...

  2. jenkins未授权访问漏洞

    jenkins未授权访问漏洞 一.漏洞描述 未授权访问管理控制台,可以通过脚本命令行执行系统命令.通过该漏洞,可以后台管理服务,通过脚本命令行功能执行系统命令,如反弹shell,wget写webshe ...

  3. Java内部类超详细总结(含代码示例)

    什么是内部类 什么是内部类? 顾名思义,就是将一个类的定义放在另一个类的内部. 概念很清楚,感觉很简单,其实关键在于这个内部类放置的位置,可以是一个类的作用域范围.一个方法的或是一个代码块的作用域范围 ...

  4. Java线程池的增长过程

    通过ThreadPoolExecutor的方式创建线程池 ThreadPoolExecutor 构造方法: public ThreadPoolExecutor(int corePoolSize, in ...

  5. PythonDay04

    ## 第四章 ### 今日内容 - 列表- 元组- range ### 列表 列表相比于字符串,不仅可以储存不同的数据类型,而且可以储存大量数据,是一种可变的数据类型 64位python的限制是 11 ...

  6. Python 环境管理

    Python 版本管理器:pyenv zsh 配置 # 安装 curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv ...

  7. 【0805 | Day 8】Python进阶(二)

    列表类型内置方法 一.列表类型内置方法(list) 用途:多个爱好.多个武器.多种化妆品 定义:[ ]内可以有多个任意类型的值,逗号分隔元素 # my_boy_friend = list(['jaso ...

  8. java8(二)方法引用

    方法引用让你可以重复使用现有的方法定义,并像 Lambda 一样进行传递. 方法引用可以被看作仅仅调用特定方法的 Lambda 的一种快捷写法. 事实上,方法引用就是让你根据已有的方法实现来创建 La ...

  9. python基础--列表,元组

    list1 = [1,2,3,4,5,6]list2 = ['wang','cong']# 1对列表中的元素取值(通过索引)print(list1[3]) # 4print(list2[1]) # c ...

  10. eclipse安装STS插件遇到的问题

    eclipse安装STS插件 第一次接触springboot,对于用惯了eclipse写代码的人来说,接受IDEA确实还要多花点时间去改变下,因为IDEA确实会节省下不必要的写代码时间.废话少说,直接 ...