CodeForces 908B New Year and Buggy Bot
1.CodeForces 1992E Novice's Mistake2.CodeForces 1935A Entertainment in MAC3.CodeForces 1992C Gorilla and Permutation4.CodeForces 1992D Test of Love5.CodeForces 1992B Angry Monk6.CodeForces 1992A Only Pluses7.CodeForces 1983B Corner Twist8.CodeForces 1983A Array Divisibility9.CodeForces 1983C Have Your Cake and Eat It Too10.CodeForces 1883B Chemistry11.CodeForces 1883A Morning12.CodeForces 1883C Raspberries13.CodeForces 1883D In Love14.CodeForces 1883E Look Back15.CodeForces 1883F You Are So Beautiful16.CodeForces 1883G1 Dances (Easy version)
17.CodeForces 908B New Year and Buggy Bot
18.CodeForces 908C New Year and Curling19.CodeForces 1132B Discounts20.CodeForces 1619D New Year's Problem21.Codeforces Round 964 (Div. 4)题目链接:CodeForces 908B【New Year and Buggy Bot】
思路
简单模拟,用pair数组存下四个方向然后,依次枚举全排列,将每个方向依次映射给0,1,2,3,然后就是跟着String走,遇到障碍或者走出地图就返回false,表示当前方案是错误的,走完String的所有指示时还没有找到出口也返回false。
代码
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 60; int n, m, len, res; vector<pair<int, int>> ve; pair<int, int> start, target; char mp[N][N]; string s; bool check(int x, int y) { if (x >= 1 && y >= 1 && x <= n && y <= m && mp[x][y] != '#') return true; else return false; } bool search() { pair<int, int> now = start; for (int i = 1; i <= len; i++) { now.first += ve[s[i] - '0'].first, now.second += ve[s[i] - '0'].second; if (check(now.first, now.second)) { if (now == target) { return true; } } else { return false; } } return false; } void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%s", mp[i] + 1); for (int j = 1; j <= m; j++) { if (mp[i][j] == 'S') { start.first = i, start.second = j; } else if (mp[i][j] == 'E') { target.first = i, target.second = j; } } } cin >> s; len = s.length(); s = " " + s; ve.push_back({0, 1}); ve.push_back({1, 0}); ve.push_back({0, -1}); ve.push_back({-1, 0}); sort(ve.begin(), ve.end()); do { if (search()) { res++; } } while (next_permutation(ve.begin(), ve.end())); cout << res << endl; return; } int main() { int t = 1; while (t--) { solve(); } return 0; }
合集:
Codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】