• Even Parity Uva 11464 ,


    写的时候多打了个叹号...  坑了很久

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    
    int main(){
    
        int answer = 0;
    
        int n;
        scanf("%d", &n);
        int mat[17][17];
        int vis[17][17];
        memset(vis, 0, sizeof(mat));
        memset(mat, 0, sizeof(mat));
    
        for (int i = 0; i < n+2; i++){
            for (int j = 0; j < n+2; j++){
                if (i == 0 || i == n+1 || j == 0 || j == n+1) {
                    mat[i][j] = 0;
                    vis[i][j] = 1;
                }
            }
        }
    
        for (int row = 1; row <= n; row++){
            for (int col = 1; col <= n; col++){
                cin >> mat[row][col];
                if (mat[row][col]) vis[row][col] = 1;
                
            }
        }
        for (;;){
            bool done = true;
            for (int row = 1; row <= n; row++){
                for (int col = 1; col <= n; col++){
                    char u = 0;
                    if (vis[row - 1][col]) u++;
                    if (vis[row + 1][col]) u++;
                    if (vis[row][col + 1]) u++;
                    if (vis[row][col - 1]) u++;
                    char sum = mat[row - 1][col] + mat[row + 1][col] + mat[row][col + 1] + mat[row][col - 1];
                    if (u == 4 && (sum % 2)) answer = -1;
                    else if (u == 3 && !(sum % 2)) {
                        if (!vis[row - 1][col]){
                            vis[row - 1][col] = 1;
                        }
                        else if (!vis[row + 1][col]){
                            vis[row + 1][col] = 1;
                        }
                        else if (!vis[row][col + 1]){
                            vis[row][col + 1] = 1;
                        }
                        else{
                            vis[row][col - 1] = 1;
                        }
                    }
                    else if (u == 3 && (sum % 2)){
                        if (answer != -1) {
                            done = false;
                            answer++;
                        }
                        if (!vis[row - 1][col]){
                            vis[row - 1][col] = 1;
                            mat[row - 1][col] = 1;
                        }
                        else if (!vis[row + 1][col]){
                            vis[row + 1][col] = 1;
                            mat[row + 1][col] = 1;
                        }
                        else if (!vis[row][col + 1]){
                            vis[row][col + 1] = 1;
                            mat[row][col + 1] = 1;
                        }
                        else{
                            vis[row][col - 1] = 1;
                            mat[row][col - 1] = 1;
                        }
    
                    }
                }
            }
            if (done) break;
        }
        printf("%d", answer);
    
        return 0;
    }
    


  • 相关阅读:
    IOS开发中实现UITableView按照首字母将集合进行检索分组
    IOS开发中设置导航栏主题
    IOS中使用.xib文件封装一个自定义View
    IOS中将字典转成模型对象
    WindowsPhone8中LongListSelector的扩展解决其不能绑定SelectdeItem的问题
    WindowsPhone8.1 开发-- 二维码扫描
    tomcat 开机自启
    redis ubuntu 开机自启
    webStorm 中使用 supervisor 调试
    ubuntu 14.04 tab失效问题
  • 原文地址:https://www.cnblogs.com/Pomodori/p/4316631.html
Copyright © 2020-2023  润新知