CodeForces - 748C Santa Claus and Robot
题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推。在此过程中留下了行走的运动轨迹,由“RLDU”表示。问若只给出运动轨迹,求最少的pi点的个数。
分析:pi到pi+1是沿最短路径走的,因此在此路径中不可能同时出现“UD”两个方向(“LR”同理)。因此只要同时出现,那一定证明此刻已往下一个目标点走。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 200000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char a[MAXN];
map<char, int> mp;
int vis[5];
void init(){
mp['L'] = 0;
mp['R'] = 1;
mp['U'] = 2;
mp['D'] = 3;
}
bool judge(int x){
if(x == 0 && vis[1]) return true;
if(x == 1 && vis[0]) return true;
if(x == 2 && vis[3]) return true;
if(x == 3 && vis[2]) return true;
return false;
}
int main(){
init();
int n;
while(scanf("%d", &n) == 1){
scanf("%s", a);
int cnt = 1;
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; ++i){
int tmp = mp[a[i]];
if(judge(tmp)){
memset(vis, 0, sizeof vis);
++cnt;
}
vis[tmp] = 1;
}
printf("%d\n", cnt);
}
return 0;
}
CodeForces - 748C Santa Claus and Robot的更多相关文章
- CodeForces 748C Santa Claus and Robot (思维)
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma ...
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- 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 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces 784B Santa Claus and Keyboard Check
题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time ...
- codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)
题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径 ...
- C. Santa Claus and Robot 思考题
http://codeforces.com/contest/752/problem/C 这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列. 对于有若干条最短路径走到第i ...
- Codeforces 748D Santa Claus and a Palindrome
雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...
随机推荐
- 浅谈JVM线程调度机制及主要策略
在之前有说过线程,应该都知道,所谓线程就是进程中的一个子任务,一个进程有多个线程.今天的话主要就是谈一谈JVM线程调度机制.我们结合线程来说,当我们在做多线程的案例时,如一个经典案例,火车站卖票. * ...
- PHP中strlen和mb_strlen函数的使用方式的不同
(1)strlen 获取字符串长度 (2)mb_strlen 使用方法: int mb_strlen ( string $str [, string $encoding ] )返回给定的字符串 ...
- 011-PHP获取数组中的元素
<?php $monthName = array( /*定义$monthName[1]到$monthName[12]*/ 1=>"January", "Feb ...
- 007-PHP变量和函数相互转换
<?php function write($text) //定义function write()函数 { print($text); //打印字符串 } function writeBold($ ...
- CSS:导航栏下拉菜单模板
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- 树莓派—raspbian软件源
零.一键换源 2018.05.18更新:新的默认源为raspbian.raspberrypi.org 因此一键换源相应改为 sudo sed -i 's#://raspbian.raspberrypi ...
- Ubuntu19.04的安装过程详解以及操作系统初始化配置
Ubuntu19.04的安装过程详解以及操作系统初始化配置 ...
- EditText监听器------实时监听
前言: 在Android开发中EditText的使用频率还是挺高的,比如登录界面输入密码验证码等,有的时候要求我们要在输入号码后显示是哪家公司的,比如中国移动,中国联通,这是就会用到EditText监 ...
- NRF51822和NRF52832的主要区别
对于NRF51822和NRF52832的选择性相信大家也是非常困惑的,哪个性价比高?下面为大家讲下NRF51822和NRF52832的一个区别,让大家能够更好的快速选型加快研发产品进度! 主要分为 ...
- 云时代架构阅读笔记九——web应用存在的问题及解决办法
web应用通常存在的10大安全问题 1.SQL注入 拼接的SQL字符串改变了设计者原来的意图,执行了如泄露.改变数据等操作,甚至控制数据库服务器, SQL Injection与Command Inje ...