题目链接: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. 【POJ - 3258】River Hopscotch(二分)

    River Hopscotch 直接中文 Descriptions 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一块岩石跳到另一块岩石.这项激动人心的活动在一条长长的笔直河道中进行,在起点 ...

  2. win10+Anaconda3+CUDA9.0+CUDNN7.1+TensorFlow-gpu1.9+Pycharm

    想在win10上运行下YOLO的例子,要先配置环境,折腾了两天,终于好了,整理下自己觉得有用且正确的流程. win10+Anaconda3+CUDA9.0+CUDNN7.1+TensorFlow1.9 ...

  3. js中slice和splice的区别

    言简意赅,直接上货. slice():该方法会返回一个新的数组,强调:新数组,并不会影响原来的数组.先来看看语法咋说:arrayObject.slice(start,end).其中,start必需,e ...

  4. vue-cli3.0创建项目报npm install --loglevel error 踩坑的那把辛酸泪

    创建项目 vue create vue-pro 然后如下图 一开始以为是npm的问题,卸载了Mac的node ,安装nvm,然后再安装node (可参考: Mac中nvm的安装和使用   https: ...

  5. c#链接数据库,查找数据信息

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. 修改 jupyter notebook的默认文件夹位置

    安装好Anaconda 3以后,就可以使用Jupyter notebook了,但是我们打开Jupyter notebook后,发现界面是一个默认的目录,这个目录在哪里?如果想把自己写的程序文件保存在自 ...

  7. springboot-jsp打jar问题

    [**前情提要**]最近做了一个项目,项目是springboot+jsp结构的,但是在发布生产环境的时候又需要用maven打成jar包,但是一开始的默认配置都不成功.下面的文章就是具体的解决过程. - ...

  8. python3从入门到精通之数据类型,布尔类型介绍

    数据的类型 为了更充分的利用内存空间以及更有效率的管理内存,变量是有不同的类型的. Number(数字) int(整型) float(浮点型) complex(复数) bool(布尔) String( ...

  9. 小白系统篇-windows 系统安装

    现阶段装系统的方法基本有几种1.硬盘安装2.光驱安装3.PE(u盘即可)安装 现在比较主流方便的用pe安装,所以我们这边就说一下PE安装系统的方法 首先我们了解下系统镜像,也就是你装系统所需得到文件( ...

  10. springboot的整合springMvc中的postman的post中的form-data和raw区别

    package com.example.demomap.Controller; import com.example.demomap.pojo.ParaEntity; import org.sprin ...