题意:机器人在网格线上行走,从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. C#中使用设置(Settings.settings) Properties.Settings.Default .(配置文件相当重要)

    C#中使用设置(Settings.settings) Properties.Settings.Default . 2016年08月04日 15:02:43 zxd9790902 阅读数:10664更多 ...

  2. 手机连接jmeter录制脚本测试

    1.准备条件 电脑安装好jmeter,准备好一个手机 注意: 电脑和手机连接的网络要一致 手机设置代理协议前要先进入想要抓取的网站: http://39.107.96.138:3000/ 2.jmet ...

  3. HDU3306-Another kind of Fibonacci(矩阵构造)

    Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  4. SQL创建表格——手写代码

    打开phpstudy,打开Navicat for MySQL,进入要创建表格的数据库,点击上方“查询”按钮,“创建查询”,即可输入代码进行创建. 例: create table class( clas ...

  5. 注解方式实例化Java类

    context:component-scan标签: Sprng容器通过context:component-scan标签扫描其base-package标签属性值指定的包及其子包内的所有的类并实例化被@C ...

  6. 吴裕雄--天生自然java开发常用类库学习笔记:线程常用的操作方法

    class MyThread implements Runnable{ // 实现Runnable接口 public void run(){ // 覆写run()方法 for(int i=0;i< ...

  7. ACM-Antiprime数

      问题描述: swust打不开,随便找了个博客.... 对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4. 定义:如果某个正整数x满足:对于任意i(0<i<x) ...

  8. NO11 SSH故障排查思路和netstat命令

    本章知识相关考试:1.企业场景面试题:Linux系统如何优化?2.企业场景面试题:SSH服务连不上,如何排查?记住回答技巧: 1 ping  2 telnet 客户端ssh工具:SecureCRT,x ...

  9. sql server 2012插入排序后的数据到临时表无效

    IF OBJECT_ID('TEMPDB..#list') IS NOT NULLBEGIN DROP TABLE TEMPDB.#list END CREATE TABLE #list(OFC_ID ...

  10. Linux学习总结《shell脚本》知识点关键-用好“过滤器”