【Good Bye 2017 B】 New Year and Buggy Bot

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

枚举一下全排列。看看有多少种可以到达终点即可。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 50;

vector <int> v;
char s[N+10][N+10];
int n,m;
pair <int,int> qidian,zhongdian;
string S;

pair <int,int> findqidian(){
    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= m;j++)
            if (s[i][j]=='S')
                return make_pair(i,j);
    return make_pair(-1,-1);
}

pair <int,int> findzhongdian(){
    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= m;j++)
            if (s[i][j]=='E')
                return make_pair(i,j);
    return make_pair(-1,-1);
}

bool ok(){
    int x = qidian.first,y = qidian.second;
    int len = S.size();
    for (int i =0;i < len;i++){
        int idx = S[i]-'0';
        idx = v[idx];
        x = x + dx[idx],y = y + dy[idx];
        if (x>=1 && x <= n && y >=1 && y <=m){
            if (x==zhongdian.first && y == zhongdian.second) return true;
            if (s[x][y]=='#') return false;
            continue;
        }else{
            return false;
        }
    }
    return false;
}

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> (s[i]+1);
    cin >> S;

    for (int i = 0;i <= 3;i++) v.push_back(i);
    qidian = findqidian();
    zhongdian = findzhongdian();

    int cnt = 0;
    do{
        if (ok()) cnt++;

    }while (next_permutation(v.begin(),v.end()));
    cout << cnt << endl;
	return 0;
}
posted @ 2017-12-30 10:51  AWCXV  阅读(164)  评论(0编辑  收藏  举报