题目链接: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. Is it a full physical image???

    My friend asked me why she could not find some important files in a physical image acquired from an ...

  2. JavaSE之——并没有多维数组

     近日在读<疯狂Java讲义>精粹第二版,部分语述摘自其中,自己边敲边理解 前言       我们知道,Java语言支持的类型有两种:            1.基本类型(即八大基本数据类 ...

  3. Oracle SQL常用内置系统函数总结

    Oracle数据库  内置系统函数主要分为以下类别:数学函数.字符串函数.日期函数.转换函数.聚合函数.分析聚合函数 一.数学函数 ------------返回数字       abs(n):返回数字 ...

  4. macOS 安装配置yaf框架 生成yaf项目

    macOS 安装配置yaf框架 Yaf只支持PHP5.2及以上的版本. 并支持最新的PHP5.3.3 Yaf需要SPL的支持. SPL在PHP5中是默认启用的扩展模块 Yaf需要PCRE的支持. PC ...

  5. Linux常用命令之ftp

    FTP是Internet用户使用最频繁的文件上传.下载的命令之一.linux ftp用命令的方式来控制在本机和远程ftp服务器之间传送文件.ftp中的命令包括上传文件(单个.多个),下载文件(单个.多 ...

  6. 从MYSQL的ibtmp1文件太大说起

    1.  啥情况呀 测试环境机器磁盘空间不足的告警打破了下午的沉寂,一群人开始忙活着删数据.但是,不久前刚清理了一波数据,测试环境在没做压测的情况下不至于短短一个月不到就涨了200G数据,于是,我悄悄的 ...

  7. SAP-批量删除生产订单

    1.SE38运行:PPARCHP1 2.先用COOIS导出订单,已经CLSD,没有删除的

  8. 阿里巴巴_java后端面经

    自我介绍不多说! 1 多线程有什么用?( 发挥多核CPU的优势 防止阻塞 便于建模 ) 2 怎么检测一个线程是否持有对象监视器( Thread类提供了一个holdsLock(Object obj)方法 ...

  9. Java开发包Jedis

    Jedis: http://www.oschina.net/p/jedis (Redis的官方首选Java开发包) <!--Redis --> <dependency> < ...

  10. .net core redis的全套操作

    Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). Redis支持主从同步.数据可以从主服务器向任意数 ...