第八届蓝桥杯c++大学A组(省赛)——第四题

时间:2023-01-20 20:01:29

真的,这么水的题目,自己考试的时候不去搜切线去搜图形,真是蠢到家了。还是经验不足。

#include <cstdio> 
#include <string> 
#include <queue> 
#include <map> 
using namespace std;  

int arr[7][7];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
long long ans;

void dfs(int x, int y){

    for (int i = 0; i<4; i++){
        if ((x+dx[i]>=0 && x+dx[i]<7) && (y+dy[i]>=0 && y+dy[i]<7) && arr[x+dx[i]][y+dy[i]] == 0){
            arr[x+dx[i]][y+dy[i]] = 1;
            arr[6-x-dx[i]][6-y-dy[i]] = 1;

            if (x+dx[i] == 0 || x+dx[i] == 6 || y+dy[i] == 0 || y+dy[i] == 6)   ans++; else dfs(x+dx[i], y+dy[i]);

            arr[x+dx[i]][y+dy[i]] = 0;
            arr[6-x-dx[i]][6-y-dy[i]] = 0;
        }
    }
}

int main() {  

    arr[3][3] = 1;
    dfs(3,3);
    printf("%d", ans/4);
    return 0;  
}