题目链接: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. java中对事务的理解

    一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库的存取. 二.事务的原则(ACID) 原子性:事务要么全部都被执行,要么就全都不被执行,如果有子事务提交失败,那么 ...

  2. [Chat]实战:仿网易云课堂微信小程序开发核心技术剖析和经验分享

    本Chat以一个我参与开发并已上线运营近2年——类似网易云课堂的微信小程序项目,来进行微信小程序高级开发的学习. 本场Chat围绕项目开发核心技术分析,帮助你快速掌握在线视频.音频类小程序开发所需要的 ...

  3. spring学习笔记之---bean管理的注解方式

    bean管理的注解方式 (一)使用注解定义bean (1)常用注解 (2)实例 1.在pom.xml中进行配置 <dependencies> <dependency> < ...

  4. codeforces679A_Bear and Prime 100 交互题

    传送门 第一道交互题 题意: 电脑事先想好了一个数[,] 你会每次问电脑一个数是否是它想的那个数的因数 电脑会告诉你yes或no 至多询问20次 最后要输出它想的数是质数还是合数 思路: 枚举< ...

  5. 后端小白的VUE入门笔记, 进阶篇

    使用 vue-cli( 脚手架) 搭建项目 基于vue-cli 创建一个模板项目 通过 npm root -g 可以查看vue全局安装目录,进而知道自己有没有安装vue-cli 如果没有安装的话,使用 ...

  6. NodeJs小试牛刀--聊天室搭建

    最近研究聊天室功能,准备用nodejs实现.下面是自己的尝试!! nodejs的安装这里就不详细赘述了. 程序创建 引入required模块 var express = require('expres ...

  7. SoapSerialization——手机号码归属地

    public class MainActivity extends AppCompatActivity { private EditText etNumber; private TextView tv ...

  8. 实现ssr服务端渲染demo

    最近在研究SSR服务器端渲染,自己写了的小demo. 项目布局 ├── build // 配置文件 │   │── webpack.base // 公共配置 │   │── webpack.clien ...

  9. 【linux】【qt5界面】【系统托盘图标的实现】

    前言: 博主最近在做一个聊天软件,虽然技术不咋滴,但遇到点干货肯定是要跟大家分享的啦.下面就给大家分享一个qt实现程序隐藏才系统托盘的技巧. 装备: 系统:linux, qt版本:5.9.2,GCC: ...

  10. 重学计算机组成原理(五)- "旋转跳跃"的指令实现

    CPU执行的也不只是一条指令,一般一个程序包含很多条指令 因为有if-else.for这样的条件和循环存在,这些指令也不会一路平直执行下去. 一个计算机程序是怎么被分解成一条条指令来执行的呢 1 CP ...