C. Santa Claus and Robot 思考题
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 思考题的更多相关文章
- 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 ...
- 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 ...
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- CodeForces 748C Santa Claus and Robot (思维)
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma ...
- codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)
题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径 ...
- CodeForces - 748C Santa Claus and Robot
题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推.在此过程中留下了行走的运动轨迹,由“RLDU”表示.问若只给出运动轨迹,求最少的pi点的个数. 分析:pi到p ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
随机推荐
- python集成开发工具
1. IDLE http://python.org/idle/ (在 Python 发行版中自带) 2 BlackAdder 3 PythonWorks 4 Wing IDE http://wingw ...
- Xcode解决代码高亮、语法提示、错误警告等功能失效的解决方法
在编写xcode的项目的时候出现过代码不高亮的症状,而且所有的warning都不再提示,include的内容也显示symbol not found,非常奇怪,解决方案如下: 方法一: 1.把.pch里 ...
- case when完成不同条件的显示
好长时间不写sql了,今天群里问了一个问题: 我想得到的就是 2,3,4,就是低,5,6,7,8,9就是中,10,11....就是高,现在只知道zpcs,怎么得到高中低? case 写的,decod ...
- WebApi:过滤器的种类
WebApi:筛选器的种类 授权筛选器:这些筛选器用于实现IAuthorizationFilter和做出关于是否执行操作方法(如执行身份验证或验证请求的属性)的安全决策.AuthorizeAttrib ...
- Android学习笔记(二)
Google在Android4.0之后加入了Action Bar的功能.但是有时候标题栏会相当占用屏幕空间,使得内容区域变小,这里演示如何隐藏标题栏. 隐藏标题栏的方法很简单,打开上节的FirstAc ...
- java内存溢出分析(一)
在项目中发现内存占用过高,且一直不会释放,top命令如下图显示 可以看到pid为17453的java进程占用27.1%内存,且长时间没有释放. 1.使用命令生成heap日志以供分析 sudo jmap ...
- 最小的K个数:用快排的思想去解相关问题
实现快速排序算法的关键在于先在数组中选择一个数字,接下来把数组中的数字分为两部分,比选择的数字小的数字移到数组的左边,比选择的数字大的数字移到数组的右边. 这个函数可以如下实现: int Partit ...
- asp.net 运行时,"未能映射路径"
asp.net 站点出现:未能映射路径,解决方案之一:发现原来是iis 应用程序池中设置了.net framework 版本为4.0了,而且VS中站点的版本为2.0引起的. 解决方案是把VS 中的站点 ...
- ThinkPHP5.0完全开发手册
http://www.kancloud.cn/manual/thinkphp5/118006 www WEB部署目录(或者子目录) ├─composer.json composer定 ...
- 数据库的索引和填充因子fillfactor
索引分为聚簇索引和非聚簇索引 1.聚簇索引/聚集索引 聚簇索引的顺序就是数据的物理存储顺序,对于一个表来说,只有一个聚簇索引 create unique clustered index id_inde ...