http://codeforces.com/contest/752/problem/C

这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列。

对于有若干条最短路径走到第i个点,这些情况可以忽略,就是你可以默认走的是任意一条最短路径。

对于一个序列,可以固定两个方向,只要一直都是这两个方向的,就不用设置点了。

比如一直都是RURURURURU,这些情况是不用设置点的,当另一个变量来的时候,比如需要D了,就需要设置一个点了。

有一些需要注意的地方是,

比如

RLL,这样只需要2个点。

RLR需要3个,

RLU需要两个。

就是本来是矛盾的两个东西,L和R矛盾,U和D矛盾。

就要考虑第三个东西,如果第三个和第一个一样的,就需要+2,其他的加1就好。

RLR第三个和第一个一样。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + ;
char str[maxn];
vector<char>vc;
bool vis[][];
void work() {
int f;
cin >> f;
vis['L']['R'] = vis['R']['L'] = ;
vis['U']['D'] = vis['D']['U'] = ;
cin >> str + ;
int ans = ;
for (int i = ; str[i]; ++i) {
if (vc.size() == ) {
bool flag = ;
for (int j = ; j < vc.size(); ++j) {
if (str[i] == vc[j]) {
flag = ;
break;
}
}
if (!flag) continue;
vc.clear();
vc.push_back(str[i]);
ans++;
} else {
bool flag = ;
for (int j = ; j < vc.size(); ++j) {
if (vc[j] == str[i]) {
flag = ;
break;
}
}
if (!flag) continue;
vc.push_back(str[i]);
if (vc.size() == ) {
if (vis[vc[]][vc[]]) {
if (i + <= f && str[i + ] != vc[]) {
ans++;
vc.clear();
vc.push_back(str[i]);
} else {
vc.clear();
ans += ;
}
}
}
}
}
if (vc.size()) ans++;
cout << ans << endl;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

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

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

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

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

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

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

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

  6. CodeForces - 748C Santa Claus and Robot

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

  7. codeforces 748E Santa Claus and Tangerines

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

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

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

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

随机推荐

  1. WorldChat.lua --世界聊天

    print(">>Script: Wolrd Chating.") local SAY=" "--普通聊天 --联盟阵营 --部落阵营 local ...

  2. latch: cache buffers chains故障处理总结(转载)

    一大早就接到开发商的电话,说数据库的CPU使用率为100%,应用相应迟缓.急匆匆的赶到现场发现进行了基本的检查后发现是latch: cache buffers chains 作祟,处理过程还算顺利,当 ...

  3. java比较两个字符串是否相等

    从c 到c++ 到 c# 到 JavaScript  判断两个字符串是否相等,用==号都可以.奇葩的java怎么可以只能用equals()这个函数.只是因为String是引用类型吗??!!哭笑不得.. ...

  4. arcgis server 10.2安装后,忘记Manager的用户名和密码

    arcgis server 10.2安装完毕后,需要创建站点,创建站点时,填写管理站点的用户名和密码.自己不小心,创建完毕后,给忘记了用户名和密码.求助Esri,解决方法如下: (1)找到arcgis ...

  5. LVS安装使用详解

    简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtualserver.org. ...

  6. JSTL的test里的逻辑判断不能有空格

    前天遇到了一个bug,有一个jstl的判断语句怎么都进不去,看了半天都没有发现什么问题,最后使用最原始的方式,一行一行的删除代码,重要找到了原因,原来是jstl的test逻辑判断里面不能有空格导致的.

  7. centos7优化mysql5.6配置

    一.环境参数 [root@hn mysql]# grep 'physical id' /proc/cpuinfo |sort -u physical id : 0 physical id : 1 [r ...

  8. Blackfin DSP(三):BF533 的EBIU接口之flash

    上一节谈了GPIO问题,是用BF561 ezkit进行说明的,这是因为561 ezkit上的GPIO是与LED直连的,讲解GPIO时不会涉及到其它问题,降低了复杂性.对于533,也采取同样的操作即可. ...

  9. C#_GDI+详细教程(图形图像编程基础)

    第7章  C#图形图像编程基础 本章主要介绍使用C#进行图形图像编程基础,其中包括GDI+绘图基础.C#图像处理基础以及简单的图像处理技术. 7.1  GDI+绘图基础 编写图形程序时需要使用GDI( ...

  10. python 中 五种字典(dict)的遍历方法,实验法比较性能。

    1 .背景: 想知道5种遍历方法,并且知道从性能角度考虑,使用哪种. 2.结论: 使用这种方式: for key,val in AutoDict.iteritems(): temp = "% ...