码迷,mamicode.com
首页 > 其他好文 > 详细

CF1207B

时间:2019-08-23 22:43:15      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:print   fine   pre   system   algorithm   std   标记   修改   center   

CF1207B-Square Filling

题意:

两个矩阵a,b,已知矩阵b,每次能修改b矩阵中相邻的四个格(b为空矩阵),使b变为a

解法:

枚举矩阵中的1,按题意修改,并把改过的四个点都标记一下。
注意每次枚举的点一定是未被标记过的,不然连pretest都过不去。

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define LL long long
#define N 60

int a[N][N],b[N][N],m,n;

int main() {
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            scanf("%d",&a[i][j]);
        }
    }
    int ans = 0;
    for(int i = 1; i < n; i++) {
        for(int j = 1; j < m; j++) {
            if(a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4) {
                b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1;
                ans++;
            }
        }
    }
    for(int i = 1; i <= n; i++)  {
        for(int j = 1; j <= m; j++) {
            if(a[i][j] ^ b[i][j]) {
                puts("-1");
                return 0;
            }
        }

    }
    printf("%d \n",ans);
    for(int i = 1; i < n; i++) {
        for(int j = 1; j < m; j++) {
            if(a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4) {
                printf("%d %d \n",i,j);
            }
        }
    }
    //system("pause");
    return 0;
}

CF1207B

标签:print   fine   pre   system   algorithm   std   标记   修改   center   

原文地址:https://www.cnblogs.com/Repulser/p/11402750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!