题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推。在此过程中留下了行走的运动轨迹,由“RLDU”表示。问若只给出运动轨迹,求最少的pi点的个数。

分析:pi到pi+1是沿最短路径走的,因此在此路径中不可能同时出现“UD”两个方向(“LR”同理)。因此只要同时出现,那一定证明此刻已往下一个目标点走。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 200000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char a[MAXN];
map<char, int> mp;
int vis[5];
void init(){
mp['L'] = 0;
mp['R'] = 1;
mp['U'] = 2;
mp['D'] = 3;
}
bool judge(int x){
if(x == 0 && vis[1]) return true;
if(x == 1 && vis[0]) return true;
if(x == 2 && vis[3]) return true;
if(x == 3 && vis[2]) return true;
return false;
}
int main(){
init();
int n;
while(scanf("%d", &n) == 1){
scanf("%s", a);
int cnt = 1;
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; ++i){
int tmp = mp[a[i]];
if(judge(tmp)){
memset(vis, 0, sizeof vis);
++cnt;
}
vis[tmp] = 1;
}
printf("%d\n", cnt);
}
return 0;
}

  

CodeForces - 748C Santa Claus and Robot的更多相关文章

  1. CodeForces 748C Santa Claus and Robot (思维)

    题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma ...

  2. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

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

  4. CF 752C. Santa Claus and Robot

    C. Santa Claus and Robot time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces 784B Santa Claus and Keyboard Check

    题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time ...

  7. codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)

    题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径 ...

  8. C. Santa Claus and Robot 思考题

    http://codeforces.com/contest/752/problem/C 这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列. 对于有若干条最短路径走到第i ...

  9. Codeforces 748D Santa Claus and a Palindrome

    雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...

随机推荐

  1. 用 ConfigMap 管理配置【转】

    Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 ConfigMap. ConfigMap 的创建和使用方式与 Secret 非常类 ...

  2. QT5安装

    Windows+Qt5.3.1+VS2013安装教程 https://blog.csdn.net/two_ye/article/details/96109876 (已成功)windows下,VS201 ...

  3. vue使用videojs控制后台m3u8数据请求

    关于Video.js的使用方法就不再说了,有兴趣的请迁跃:https://videojs.com/ VideoJS中并没有stop之类控制后台数据请求的参数,只有暂停 video.pause()方法 ...

  4. java#类的实例化顺序

    关于类的实例化,不用弄的那么细致,这里只说单一类,没有其他父类(排除Obejct)的情况.要实例化一个类,需要加载class文件到jvm并且验证通过了是安全的字节码文件. 初始化大致上是按照如下步骤: ...

  5. 我的C语言的新开端<graphics.h>

    进一步接触C语言<graphics.h> #include<stdio.h> #include<graphics.h> #include<conio.h> ...

  6. 014、Java中byte自动转型的操作

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  7. Python中基于Unpacking与Packing进行分割,组合操作的嵌套元组数据结构的应用

    对于二叉树,图等,Python可采用基于Packing与Unpacking形成的嵌套元组数据结构来模拟,这里Packing指,比如a=b,c则,a就成了一个包含b,c的元组,Unpacking是指,比 ...

  8. WEB前段(HTML+JS),后端(MYSQL+PHP)开发基础

    一.HTML HTML:超文本标记语言,可以加载JS/CSS/图片/链接等非文字的内容 一切的网页开发技术都需要建立在HTML的基础之上 HTML的结构和语法 HTML元素 注释:  <!-- ...

  9. 小程序分享报错 Cannot read property 'apply' of null;at page XXX onShareAppMessage function

    Cannot read property 'apply' of null;at page XXX onShareAppMessage function 然后看了下自己的代码,分享按钮在子组件里, at ...

  10. java核心-JVM-gc面试题

    1.写一个memory leak的例子 public class MemonyLeak { //1.memoryLeak内存泄漏 /* 这类错误报错具体显示:java.lang.OutOfMemory ...