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 ...
随机推荐
- hmtl 中的定位
1.绝对定位: position:sbsolute: 作用:将元素从文档流中拖出来,然后使用 left,right,top,bottom属性相对于其最接近的一个具有定位属性的父包含块进行绝对定位. 若 ...
- js中的this指针(四)
当一个函数前面加上 new 操作符来调用,此时 this 会被绑定到新生成的对象上. 这既是所谓的构造函数调用模式.
- mysql系统库INFORMATION_SCHEMA,MySQL,TEST,mysql系统表的作用
本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TEST三个数据库的用途. 第一个数据库INFORMATION_SCHEMA: 提供了访问数据库元数据的方 ...
- 用DotNetBar设计的 Gradient Buttons 漂亮按钮
http://www.webdesignerwall.com/demo/css-buttons.html public class GradientButtons : DevComponents ...
- 解决TalbleView头部或底部子控件不显示问题
在自定义cell头部控件UITableViewHeaderFooterView(和自定义cell的方法几乎一样)时,出现了头部控件子控件不显示的问题. 注意和自定义cell的区别. .h文件 #imp ...
- C# : Post 接收或发送XML
项目分成两个 web(ASP.Net)用户处理请求,客户端(wpf/winform)发送请求 1.web项目 有两个页面 SendPost.aspx(单纯发送数据给客户端) 代码: public pa ...
- 初学RabbitMQ
一.RabbitMQ中的一些概念 (1)Connection(连接) 与RabbitMQ建立连接,由ConnectionFactory创建每个Connection至于一个物理server进行连接,此链 ...
- 【转载】芯片级拆解51、AVR、MSP430、凌阳61、PIC,5种单片机,多张显微照片
先秀一张解剖照,放大裁剪,小米1S微距拍摄,800万像素摄像头很给力!今天等待被拆的是5个单片机芯片:(1)凌阳16位单片机SPCE061A ,这是我接触的第一个单片机,最高主频49MHz,32KB的 ...
- OAF_文件系列4_实现OAF上传显示数据库动态图片Image(案例)
20150805 Created By BaoXinjian
- [家里蹲大学数学杂志]第432期Hardy type inequalities
If $p>1$, $f\geq 0$, and $$\bex F(x)=\int_0^x f(t)\rd t, \eex$$ then $$\bee\label{Hardy:0 to x} \ ...