http://codeforces.com/contest/908/problem/B

0 1 2 3 可以对应 上下左右。(具体哪个对应哪个,试过才知道)

str 的 长度 为 100,0 1 2 3 的全排列一共24种,最坏的情况可以看成遍历长为2400的字符串,不会超时

然后就暴力+next_permutation即可

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>using namespace std;char map[52][52];
char str[102];
int a[] = {0,1,2,3};
int x[] = {0,0,1,-1};
int y[] = {1,-1,0,0};
int x0,y0;
int sum = 0;
int n,m;void solve()
{int i,len = strlen(str);do{int xx = x0;int yy = y0;for(i=0;i<len;i++){xx += x[a[str[i]-'0']];yy += y[a[str[i]-'0']];if(xx>=n || xx<0 || yy>=m || yy<0 || map[xx][yy]=='#'){break;}if(map[xx][yy]=='E'){sum++;//cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;break;}    }}while(next_permutation(a,a+4));
}int main ()
{cin >> n >> m;getchar();int i,j;for(i=0;i<n;i++){for(j=0;j<m;j++){cin >> map[i][j];if(map[i][j] == 'S'){x0 = i;y0 = j;}}getchar();}cin >> str ;solve();cout << sum << endl;return 0;
}

【Codeforces】908B New Year and Buggy Bot(暴力+全排列)相关推荐

  1. Codeforces 908 B. New Year and Buggy Bot

    B. New Year and Buggy Bot 思路:使用全排列函数,{0,1,2,3}共24种情况. #pragma GCC optimize(1) #pragma GCC optimize(2 ...

  2. CodeForces - 1501C Going Home(鸽巢原理+暴力)

    题目链接:点击查看 题目大意:给出 nnn 个数,问是否存在四个数满足:a+b=c+da+b=c+da+b=c+d 题目分析:官方题解是直接 O(n2)O(n^2)O(n2) 暴力,因为每个数的范围是 ...

  3. Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

    原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...

  4. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...

  5. codeforces 465 C. No to Palindromes!(暴力+思维)

    题目链接:http://codeforces.com/contest/465/problem/C 题意:给出一个不存在2个或以上回文子串的字符串,全是由小写字母组成而且字母下表小于p,问刚好比这个字符 ...

  6. CodeForces - 731D 80-th Level Archeology(线段树+暴力/差分)

    题目链接:点击查看 题目大意:给出 n 个数列,再给出一个模数 mod,每次操作可以将所有的数字进行:x = x %mod + 1 操作,问至少进行多少次操作,才能使得 n 个数列按照字典序非降序排列 ...

  7. 【CodeForces - 761C】Dasha and Password (暴力可过,标解dp,字符串,有坑总结)

    题干: After overcoming the stairs Dasha came to classes. She needed to write a password to begin her c ...

  8. Codeforces 986A. Fair(对物品bfs暴力求解)

    解题思路: 1. 对物品i bfs,更新每个小镇j获得每个物品i的最短距离. 2. 时间复杂度o(n* k*logk),满足2s的要求. 代码: #include <iostream> # ...

  9. 【CodeForces - 633D】Fibonacci-ish (离散化,暴力枚举+STPmap,fib数列收敛性质)

    题干: Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a s ...

最新文章

  1. [模板]tarjan求强连通分量
  2. 剑指offer23 从上往下打印二叉树
  3. Android 去掉TabLayout下的阴影,AppBarLayout下的阴影
  4. $2019$ 暑期刷题记录 $2$(基本算法专题)
  5. 东莞.NET技术线下沙龙活动资料分享
  6. slr1文法_SLR的完整形式是什么?
  7. c# 中如何设置combox 让出现text value两个值 winform开发
  8. 【华为云技术分享】自动网络搜索(NAS)在语义分割上的应用(二)
  9. java数组表格输出_Java 如何将数组中的数据以表格形式输出
  10. vSphere 高级特性FT配置与管理
  11. NUnit的使用中可能遇到的问题
  12. 视频教程-R语言入门基础-大数据
  13. 一文看懂中国银联CUPS清结算流程
  14. 初中计算机考试知识,初中信息技术学业考试《基础知识复习提纲》
  15. Python将base64编码转换为图片并存储
  16. GMap.NET控件使用
  17. Spring 全家桶,永远滴神
  18. 轮流取石子游戏c语言答案,取石子游戏
  19. 云服务器挖矿病毒解毒方案
  20. VSC | vscode 常用快捷键

热门文章

  1. 参加软件测试培训前景怎么样
  2. 使用树形结构保存实体
  3. 网络工程师成长日记333-某城市政府项目
  4. MQTT的学习研究(五) MQTT moquette 的 Blocking API 发布消息服务端使用
  5. 如何在JSP页面中获取当前系统时间转
  6. 菜鸟学***——菜鸟的旅程
  7. 我对bgwriter.c 与 guc 关系的初步理解
  8. IronPython系列:Composite Pattern及其实现
  9. 利用三层交换机实现VLAN的通信实验报告
  10. Error Creating Control when creating a custom control