zoukankan      html  css  js  c++  java
  • [蓝桥杯每日一题]1.3 & 1.4

    2017省赛A组 1题

    题目链接

    #include <bits/stdc++.h>
    using namespace std;
    
    /*
        蓝桥杯2017A_1
        算法:DFS
    */
    
    void file()
    {
        #ifdef ONLINE_JUDGE
        #else
            freopen( "d:/workProgram/test.txt","r",stdin );
        #endif
    }
    
    int dx[4] = {0,1,0,-1};///d[0] = 'U',d[1] = 'L',d[2] = 'D',d[3] = 'R'
    int dy[4] = {1,0,-1,0};
    char g[12][12] = {0};
    int st[12][12] = {0};//如果以前以用这个点走到了终点则不用计算了
    
    int ans = 0;//最后的结果
    
    void dfs(int x , int y)
    {
    
        if( x > 10 || x < 1 || y > 10 || y < 1 ){
            ans ++ ;
            return ;
        }
    
        if( st[x][y] == 1 ) return ;
        st[x][y] = 1;
    
    
        if( g[x][y] == 'U' ){
            dfs( x-1, y );
        }
        else if( g[x][y] == 'L' ){
            dfs( x , y-1 );
        }
        else if( g[x][y] == 'D' ){
            dfs( x+1 , y );
        }
        else if( g[x][y] == 'R' ){
            dfs( x , y+1 );
        }
    
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    
        file();
    
        //读入
        for(int i = 1; i <= 10; i++)
            for(int  j =  1; j <= 10; j++)
            cin >> g[i][j];
    
        for(int i = 1; i <= 10; i++){
            for(int j = 1; j <= 10; j++){
                memset(st,0,sizeof(st));
                dfs( i,j );
                //cout << g[i][j];
            }
            //cout << endl;
        }
        cout << ans << endl;
    
        return 0;
    }
    
    
  • 相关阅读:
    日报10.11
    日报10.9
    日报10.8
    日报10.7
    换马甲啦
    CSP2019知识点整理
    字符logo存档
    QHDYZ模拟赛20191027 提前透题
    数竞大佬jhc的三角函数复习题
    IO流
  • 原文地址:https://www.cnblogs.com/hoppz/p/14253270.html
Copyright © 2011-2022 走看看