简单题求调
  • 板块学术版
  • 楼主Lovely_Elaina
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/4/1 09:36
  • 上次更新2023/10/23 19:52:47
查看原帖
简单题求调
781159
Lovely_Elaina楼主2023/4/1 09:36

#include <bits/stdc++.h>
// #include <iostream>
// #define int long long
// #define max(a,b) (a>b?a:b)
// #define min(a,b) (a<b?a:b)
using namespace std;
const int N = 105;

const int tx[4] = {1,0,-1,0};
const int ty[4] = {0,1,0,-1};

struct node{
    bool l = false;
    int a,b;
}a[N][N];

int n,m,c = 1;
bool k = 1;
bool b[N][N];

inline void dfs(int x,int y){
    b[x][y] = 1;
    
    if(!a[a[x][y].a][a[x][y].b].l){
        c++,k = 1;
        a[a[x][y].a][a[x][y].b].l = 0;
    }
    
    for(int i = 0; i < 4; i++){
        int fx = x+tx[i];
        int fy = y+ty[i];
        
        if(!b[x][y]){
            a[fx][fy].l = 1;
            dfs(fx,fy);
        }
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    cin >> n >> m;
    
    a[1][1] = {1,0,0};
    
    int tx,ty,ta,tb;
    for(int i = 1; i <= m; i++){
        cin >> tx >> ty >> ta >> tb;
        a[tx][ty].a = ta;
        a[tx][ty].b = tb;
        
        //if(a[tx][ty].l){
        //    c++;
        //    a[ta][tb].l = 1;
        //}
    }
    
    while(k){
        memset(b,1,sizeof(b));
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                if(a[i][j].l) b[i][j] = 0;
            }
        }
        k = 0;
        dfs(1,1);
    }
    
    cout << c << endl;
    return 0;
}
2023/4/1 09:36
加载中...