题意:机器人在网格线上行走,从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;
}

  

转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/6486438.html

CodeForces - 748C Santa Claus and Robot相关推荐

  1. 【codeforces 752C】Santa Claus and Robot

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

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

  3. CodeForces 748D Santa Claus and a Palindrome

    CodeForces 748D Santa Claus and a Palindrome 题目描述 Santa Claus likes palindromes very much. There was ...

  4. codeforces D Santa Claus and a Palindrome(hash+贪心)

    思路:计算字符串的正反哈希值.如果字符串不是回文串,并且存在字符串的反串,将这两上串作为构成回文串的两边.如果字符串是回文串,一种是将其作为回文串的中间,另外一种是作为回文串的对称串来处理. 具体代码 ...

  5. Santa Claus and a Palindrome

    Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...

  6. Dear Santa Claus圣诞老人创意字体 for mac

    Dear Santa Claus Font是一种甜美而友好的手写字体.看起来好像是孩子的笔迹,因此,此圣诞老人创意Mac字体将是写给圣诞老人的信或给您的作品增添些许纯真的完美选择.Mac圣诞老人创意字 ...

  7. UVA 291 The House Of Santa Claus(DFS/深搜)

    The House Of Santa Claus Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  8. Android2018年必须知道的史上最全框架、最全开源App(高级开发人员必看,面试必看)

    声明: 查看全文 http://www.taodudu.cc/news/show-5255667.html 相关文章: Android2018年必须知道的史上最全框架.最全开源App 又是一个好资源个 ...

  9. linux内核设计与实现 怎么读,《Linux内核设计与实现》CHAPTER1,2阅读梳理

    jedis支持哨兵主从配置role为slave jedis功能强大,但是不能像nodejs一样指定从slave中读数据,使数据量读写量较大时读写分离,减少redis压力. 我们可以利用jedis中的方 ...

  10. Codeforces Round #101 (Div. 2)

    C.Queue(模拟) C.Queue(模拟) TimeLimit:2000MSMemoryLimit:262144KB Time\quad Limit:2000MS\quad Memory\quad ...

最新文章

  1. windows 10 anaconda python 3.7 安装keras-gpu tensorflow-gpu
  2. vb小工具-----txt转为excel
  3. 分别用顺序表和链表实现队列
  4. 【opencv】图像细化
  5. each 数据获取attr_我背着CSDN偷偷记录了大半年我博客数据
  6. linux java获取文件创建时间_Linux查看文件的最初创建时间
  7. 一个注册为输入法的木马分析
  8. 设计模式笔记五:原型模式
  9. Linux学习笔记016---CentOS7虚拟机设置使用静态IP上网_配置集群的时候可以用
  10. svm 文本分类 matlab,livsvm文本分类总结详解
  11. 190515每日一句
  12. 一篇文章教你如何刷Letcode进大厂
  13. Go中chan引发的协程死锁
  14. 互联网系统故障应急处理流程
  15. w ndoWs8pE模式下载,天意PE迷你版V2011.9.9(天意PE系统)下载 - 下载吧
  16. 【Android 系统开发】CyanogenMod 13.0 源码下载 编译 ROM 制作 ( 手机平台 : 小米4 | 编译平台 : Ubuntu 14.04 LTS 虚拟机)
  17. Elasticsearch镜像打包记录
  18. 心情顿时很失落的感觉!
  19. 将远程桌面连接的快捷方式发送到电脑桌面上
  20. 【软件简史】怎样理解 Alan Kay 曾在1984 年写道:“我们希望像以前编辑文档一样编辑我们的工具” 这句话 —— LLM 将如何影响软件的创建?

热门文章

  1. springboot学习笔记1
  2. C++学生信息管理系统5.0
  3. windows无法安装iis信息服务器,windows server 2016 安装iis教程
  4. html视频播放快进按钮,【浏览器插件】Video Speed Controller – 网页视频倍速、快进、回放功能0.07~16 倍...
  5. linux安装向日葵命令行版
  6. 复杂网络学习的一些常用数据集
  7. pandasql库学习使用之在Python中执行SQL语句
  8. Python获取sklearn库中iris数据写入本地csv文件,可视化展示数据并进行分类、聚类实验以及结果可视化
  9. 计算机网络协议到底分几层,一次讲清楚
  10. 后现代婚礼机器人显神通_机器人+无人机 江西新余智能消防显“神通”