题意:机器人在网格线上行走,从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. spring-boot-autoconfigure-xx.jar核心注解

  2. jsp获取web的跟路径

    我实现了一个listener,此listener在tomcat启动的时候读取项目的配置文件,配置文件是xml.但是读取解析的功能是在另一个工具类实现的. 这个普通的工具类B,如何获取到当前web的跟路 ...

  3. [Codeforces] #603 (Div. 2) A-E题解

    [Codeforces]1263A Sweet Problem [Codeforces]1263B PIN Code [Codeforces]1263C Everyone is a Winner! [ ...

  4. tp5日志分表

    /** * 记录网站日志 * * @return bool */ public function record() { // 组装数据 $log = self::$param; $log[self:: ...

  5. JuJu团队11月25号工作汇报

    JuJu团队11月25号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 于达 实现随机采样函数,进行onehot处理 预处理数据集,将数据集转为矩阵读入 数据集预处理比想象中麻 ...

  6. POJ 3007:Organize Your Train part II

    Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7561   Acce ...

  7. TS-Lint 安装方法

    1  在 Visual Studio Extensions  里下载 TSLint  2  在项目根目录下放 tslint.json 文件 (里面的规则定死就好 我认为没有特别大的意义)

  8. nodejs常用模块

    推荐的入门教程: <七天学会NodeJS>  https://github.com/nqdeng/7-days-nodejs <Node.js 包教不包会> https://g ...

  9. 博客已经转到www.vsyf.me/blog

    租了个服务器,重搭了个博客 阿发的博客

  10. SpringBoot#自定义配置的封装

    _震惊,开局 不可避免的需要弄一些自定义的配置. 要点: 1. 把配置项都写出来,分析层次关系:2. 抽象成bean与bean之间的关系,写出bean对应的类,这时候配置项对应了bean的属性,属性可 ...