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 ...
随机推荐
- Bean
1. Bean配置项 1.1. ID 在整个IOC容器中Bean的唯一标识 1.2. Class 具体要实例化的类 1.3. Scope 范围,作用域 1.4. Constructor argumen ...
- Ioc正解
IoC是一种模式 IoC(Inversion of Control)中文译为控制反转,目前Java社群中流行的各种轻量级容器的实现都是以IoC模式作为基础的.控制反转意味着在系统开发过程中,设计的类将 ...
- VS2013添加使用lib的方法
使用第三方厂家的库,一般都会有三个文件: xxx.h xxx.lib xxx.dll 头文件很明显,就在需要用到的文件里面include就好. lib文件,可以直接在IDE中添加,具体步骤有两个: 1 ...
- Spring MVC 4.2 增加 CORS 支持 Cross-Origin
基于XML的配置: <mvc:cors> <mvc:mapping path="/api/**" allowed-origins="http://dom ...
- springmvc权限过滤器
package com.zbb.cn.filter; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; ...
- Win32程序和控制台应用程序的项目互转设置
一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...
- iOS中定时器的使用
1. NSTimer 不是很精确 2.CADisplayLink 屏幕 3.通过GCD来实现定时间器 //定时循环执行事件 //dispatch_source_set_timer 方法值得一提的是最后 ...
- [家里蹲大学数学杂志]第269期韩青编《A Basic Course in Partial Differential Equations》 前五章习题解答
1.Introduction 2.First-order Differential Equations Exercise2.1. Find solutons of the following inti ...
- SQL Error (1130): Host '192.168.1.126' is not allowed to connect to this MySQL server
通过HeidiSQL连接MYSQL数据库报错: SQL Error (1130): Host '192.168.1.126' is not allowed to connect to this MyS ...
- JavaScript中Math--random()/floor()/round()/ceil()
Math.random():返回0-1之间的任意数,不包括0和1: Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入:例子:Math.floor(1.0);Mat ...