zoukankan      html  css  js  c++  java
  • 【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;
    }
    
  • 相关阅读:
    bzoj3159: 决战
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) A
    loj 6401 字符串
    BZOJ5194 雪地靴
    BZOJ 4709 柠檬
    BZOJ 3343 魔法
    [8月16日绍兴]试剂
    设备塔
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8149039.html
Copyright © 2011-2022 走看看