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 ...
随机推荐
- JS(去掉前后空格或去掉所有空格)的用法 推荐使用jquery 方法
说明: 如果使用jQuery直接使用$.trim(str)方法即可,str表示要去掉前后所有空格的字符串. 推荐 1. 去掉字符串前后所有空格: 代码如下: function Tri ...
- IDEA 中 显示 *.properties 为中文
效果:
- Windows 10的TPM模块到底是不是美国全球监控体系的奠基石?
http://bbs.pediy.com/showthread.php?t=202638 http://www.zhihu.com/topic/19671262/newest 2015年3月18日,微 ...
- 化繁为简 如何向老婆解释MapReduce?(转载)
化繁为简 如何向老婆解释MapReduce? 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解MapReduce的概念(根据他们的反馈).我成功 ...
- python数据分析之pandas库的DataFrame应用一
DataFrame是一个表格型的数据结构,它含有一组有序的列,每列可以是不同的值类型(数值,字符串,布尔型).DateFrame既有行索引也有列索引,可以被看作为由Series组成的字典. 构建Dat ...
- MyEclipse Spring 学习总结三 SpringMVC
MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...
- .Net操作Excel
先去官网:http://npoi.codeplex.com/下载需要引入dll(可以选择.net2.0或者.net4.0的dll),然后在网站中添加引用. .Net导出代码: /// <summ ...
- [JBoss] - 在Jboss 7.1 AS中打印hibernate的SQL方法
因为JBoss使用的是log4j,JBoss的系统日志级别默认是INFO.而Hibernate或IBatis要打印SQL,级别为DEBUG,所以,程序设置了log4j级别为DEBUG会被JBoss系统 ...
- List<T>线性查找和二分查找BinarySearch效率分析
今天因为要用到List的查找功能,所以写了一段测试代码,测试线性查找和二分查找的性能差距,以决定选择哪种查找方式. 线性查找:Contains,Find,IndexOf都是线性查找. 二分查找:Bin ...
- < 独立项目 - 文本挖掘 > - 2016/10/25 第一更 - <Linux相关知识准备>
< 独立项目 - 文本挖掘 > 项目立项的相关背景介绍,TODO方向. 一.Ubuntu环境配置 主机系统:Windows 7 SP1 64位操作系统 | i5-4210 CPU | ...