CodeForces 748C Santa Claus and Robot (思维)
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线。
析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
map<char, int> mp;
mp['L'] = 0; mp['U'] = 1; mp['D'] = 2; mp['R'] = 3;
string s;
cin >> n >> s;
if(1 == n){ cout << "1\n"; return 0; }
int ans = 0;
int dx = 0, dy = 0, pos = 0;
for(int i = 0; i < s.size(); ++i){
if(s[i] == 'U'){
if(dy >= 0) dy = 1;
else ++ans, dy = 1, dx = 0;
}
else if(s[i] == 'D'){
if(dy <= 0) dy = -1;
else ++ans, dy = -1, dx = 0;
}
else if(s[i] == 'L'){
if(dx <= 0) dx = -1;
else ++ans, dx = -1, dy = 0;
}
else{
if(dx >= 0) dx = 1;
else ++ans, dx = 1, dy = 0;
}
}
++ans;
printf("%d\n", ans);
return 0;
}
CodeForces 748C Santa Claus and Robot (思维)的更多相关文章
- CodeForces - 748C Santa Claus and Robot
题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推.在此过程中留下了行走的运动轨迹,由“RLDU”表示.问若只给出运动轨迹,求最少的pi点的个数. 分析:pi到p ...
- 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个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...
随机推荐
- 移动端,多屏幕尺寸高清屏retina屏适配的解决方案
移动端高清.多屏适配方案 背景 开发移动端H5页面 面对不同分辨率的手机 面对不同屏幕尺寸的手机 视觉稿 在前端开发之前,视觉MM会给我们一个psd文件,称之为视觉稿. 对于移动端开发而言,为了做到页 ...
- inception安装步骤---自己整理的安装步骤
inception安装步骤---自己整理的安装步骤2015-09-18 15:51 6185人阅读 评论(1) 收藏 举报 分类: inception相关版权声明:本文为博主原创文章,未经博主允许不得 ...
- Linux中进程的优先级
Linux採用两种不同的优先级范围,一种是nice值.还有一种是实时优先级. 1.nice值 nice值得范围是-20~19,默认值是0. 越大的nice值意味着更低的优先级.也就是说nice值为-2 ...
- JavaScript读书笔记(3)-操作符、语句和函数
1. 操作符 (1) 一元操作符 前置递增和递减操作符,变量的值都是在语句被求值以前改变的:后置相反 (2) 位操作符 在ECMAScript中,对数值进行位操作时,会发生以 ...
- 阿里云nginx+thinkphp环境运行会直接下载php文件的问题。
测试了好久,在网上查了各种nginx.conf的虚拟机配置都没用 其实最简单的方法就是在php.ini中找到 #cgi.fix_pathinfo=1; 去掉前面的#,如果值不是1则改为1
- Asp.Net Core 初探 (三)
昨天失败的生产环境部署就先放着,明天再解决! 今天利用中午的空余时间看了一下Asp.net core 的Areas . 相对于Asp.net MVC5 以及之前的版本,asp.net core 的Ar ...
- .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点
除了使用.net里面提供的内置处理程序来处理我们的自定义节点外,我们还可以通过多种方法,来自己定义处理类处理我们的自定义节点,本文主要介绍通过实现IConfigurationSectionHandle ...
- 主题:iframe高度的自适应
在项目开发中,遇到的一个问题.弹出的页面中有iframe.例 <iframe src="www.baidu.html" width="100%" char ...
- Xcode 6 IDE
本文转载至 http://www.cocoachina.com/ios/20140823/9442.html (via:苹果开发者中心) Xcode IDE 是 Apple 开发体验的核心.X ...
- EasyDarwin开源流媒体服务器将select改为epoll的方法
本文来自EasyDarwin团队Fantasy(fantasy(at)easydarwin.org) 一. EasyDarwin网络模型介绍 EventContext负责监听所有网络读写事件,Even ...