codeforces748c-Santa Claus and Robot
2017-03-02 13:16
417 查看
题目链接:https://vjudge.net/problem/CodeForces-748C
题目大意:
这道题的意思是一个机器人会沿路径最短的路走到每一个目标点,但是现在已经不知道哪里有目标点了,但是记录下来机器人的行走方向。请根据行走方向还原出最少需要多少个目标点机器人会这样行走。
题目分析:
这道题的第一周第一场训练的一道题,至今不知道用到了什么算法,听大佬们说这其实就是个走迷宫的问题。我当时没看懂这个题是什么意思,赛后根据给出的提示大致猜出了这道题的意思。如果一个机器人一直在向左走,突然选择了改变方向,那说明在这个方向上可能存在一个点。用两个变量分别记录其在左右和上下方向上的运动,然后逐一判断即可。
给出代码:
题目大意:
这道题的意思是一个机器人会沿路径最短的路走到每一个目标点,但是现在已经不知道哪里有目标点了,但是记录下来机器人的行走方向。请根据行走方向还原出最少需要多少个目标点机器人会这样行走。
题目分析:
这道题的第一周第一场训练的一道题,至今不知道用到了什么算法,听大佬们说这其实就是个走迷宫的问题。我当时没看懂这个题是什么意思,赛后根据给出的提示大致猜出了这道题的意思。如果一个机器人一直在向左走,突然选择了改变方向,那说明在这个方向上可能存在一个点。用两个变量分别记录其在左右和上下方向上的运动,然后逐一判断即可。
给出代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <set> #include <map> #include <string> #include <cmath> #include <vector> #include <cstring> using namespace std; map<char,char> place; int main() { int n; cin>>n; string a; cin>>a; int lr=0,tb=0; int sum=1; for(int i=0; i<a.length(); i++) { if(a[i]=='R') { if(lr==0||lr==2) { lr=2; continue; } else { lr=2; tb=0; sum++; } 4000 } if(a[i]=='L') { if(lr==0||lr==1) { lr=1; continue; } else { lr=1; tb=0; sum++; } } if(a[i]=='U') { if(tb==0||tb==1) { tb=1; continue; } else { tb=1; lr=0; sum++; } } if(a[i]=='D') { if(tb==0||tb==2) { tb=2; continue; } else { tb=2; lr=0; sum++; } } } // sum++; cout<<sum<<endl; return 0; }
相关文章推荐
- 748 C. Santa Claus and Robot codeforces
- 748C Santa Claus and Robot
- CodeForces - 748C Santa Claus and Robot(思维)
- Codeforces 752C Santa Claus and Robot 思维
- 【Codeforces 748 C Santa Claus and Robot】+ 思维
- Codeforces Round #389(Div.2)C Santa Claus and Robot【思维】
- 【Codeforces Round #389】Codeforces 752C Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- Codeforces Round #389 Div.2 C. Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- C. Santa Claus and Robot 思考题
- CodeForces 748C Santa Claus and Robot (思维)
- 748C Santa Claus and Robot
- Codeforces Round #389 Technocup 2017 E. Santa Claus and Tangerines(二分+DP)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- B - Santa Claus and Keyboard Check CodeForces - 748B
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)