CF1207B Square Filling


代码存档

#include <bits/stdc++.h>
#define maxn 100
using namespace std ;
int n , m , flag = 0 , tim ;
struct dy{
	int x , y ;
}ans[maxn*maxn] ;
int a[maxn][maxn] , vis[maxn][maxn] ;
int check(int x,int y) {
	if(a[x+1][y] && a[x][y+1] && a[x+1][y+1]) 
		return 1 ;
	return 0 ;
}
void change(int x,int y) {
	vis[x][y] = true ;
	vis[x+1][y] = true ;
	vis[x][y+1] = true ;
	vis[x+1][y+1] = true ;
}
int main () {
	cin >> n >> m ;
	for(int i = 1 ; i <= n ; i ++) {
		for(int j = 1 ; j <= m ; j ++) {
			cin >> a[i][j] ;
			if(a[i][j]) flag = 1 ;
		}
	}
	if(!flag) {
		puts("0") ;
		return 0 ;
	}else {
		for(int i = 1 ; i <= n ; i ++) {
			for(int j = 1 ; j <= m ; j ++) {
				if(a[i][j]) {
					if(check(i,j)) {
						ans[++tim].x = i ;
						ans[tim].y = j ;
						change(i,j) ;
					}else if(!vis[i][j]){
						puts("-1") ;
						return 0 ;
					}
				}
			}
		}
	}
	cout << tim << endl ;
	for(int i = 1 ; i <= tim ; i ++) {
		cout << ans[i].x << " " << ans[i].y << endl ;
	}
	return 0 ;
}

溜了溜了

原文地址:https://www.cnblogs.com/lyt020321/p/11402002.html