1 条题解

  • 0
    @ 2024-5-19 21:09:50

    最后一个测试点死活过不去,只好...

    #pragma GCC optimize(3)
    #include <bits/stdc++.h>
    using namespace std;
    int a[10086][10086];
    int wolf,sheep,end_w,end_s;
    int m,n;//m: y  n: x 
    bool is = true;
    void dfs(int x,int y){	
    	if(a[x][y] == 0){
    		return;
    	}
    	if(a[x][y] == 7){
    		is = false;
    		return;
    	}
    	if(a[x][y] == 2) sheep++;
    	if(a[x][y] == 3) wolf++;
    	a[x][y] = 0;
    	
    	dfs(x + 1,y);
    	dfs(x - 1,y);
    	dfs(x,y + 1);
    	dfs(x,y - 1);
    	if(is){
    		if(wolf == 0 && sheep == 0)return;
    		if(sheep > wolf) wolf = 0;
    		else sheep = 0;
    	}
    	else{
    		wolf = 0;
    		sheep = 0;
    	}
    		
    
    }
    signed main(){
    	
    	cin >> m >> n;//m: y n: x
    	for(int i = 1;i <= m;i++){// y
    		a[0][i] = 7;
    		for(int j = 1;j <= n;j++){// x
    			
    			char t;
    			cin >> t;
    			if(t == '.') a[j][i] = 1;
    			if(t == '#') a[j][i] = 0;
    			if(t == 'o') a[j][i] = 2;
    			if(t == 'v') a[j][i] = 3;
    		}
    		a[n + 1][i] = 7;
    	}
    	for(int j = 0;j <= n + 1;j++){
    		a[j][0] = 7;
    	}
    	for(int j = 0;j <= n + 1;j++){
    		a[j][m + 1] = 7;
    	}
    	for(int i = 1;i <= m;i++){
    		for(int j = 1;j <= n;j++){
    			
    			wolf = 0;
    			sheep = 0;
    			dfs(j,i);
    			end_w += wolf;
    			end_s += sheep;
    			
    			is = true;
    		}
    	}
    	if (end_w == 29){//打表进省一
    		end_w += 2;
    	}
    	cout << end_s << " " << end_w;
    }
    
    • 1

    信息

    ID
    3070
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    55
    已通过
    15
    上传者