`
king_tt
  • 浏览: 2274962 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

uva 11464 Even Parity

 
阅读更多

链接:

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2459


思路:

这题因为题目没理解好,以为是要让每个格子周围的九个数字之和为偶数。。。导致了想了好久没想出。后来才发现原来只是上,下,左,右...

其实就是暴力穷举,枚举第一行可以变化的情况,然后根据第一行依次求出后面行的情况。注意1不能变为0.



#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const int INF = 0x3f3f3f;
const int maxn = 20;
int n;
int mat[maxn][maxn];
int B[maxn][maxn];


int check(int s){
    memset(B, 0, sizeof(B));
    for(int i=1; i<=n; ++i){
        if(s & (1<<(i-1))) B[1][i]=1;
        else if(mat[1][i]) return INF;
    }
    for(int i=2; i<=n; ++i){
        for(int j=1; j<=n; ++j){
            int sum = B[i-2][j]+B[i-1][j-1]+B[i-1][j+1];
            B[i][j] = sum&1;
            if(mat[i][j] && B[i][j]==0) return INF;
        }
    }
    int cnt=0;
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=n; ++j)
            if(mat[i][j] !=B[i][j]) ++cnt;
    return cnt;
}


int main(){
    
    int T;
    scanf("%d", &T);
    memset(mat, 0, sizeof(mat));
    
    for(int cas=1; cas<=T; ++cas){
        
        scanf("%d", &n);
        
        for(int i=1; i<=n; ++i)
            for(int j=1; j<=n; ++j)
                scanf("%d",&mat[i][j]);

        int ans = INF;
        for(int s=0; s<(1<<n); ++s)
            ans = min(ans, check(s));

        if(ans == INF)  ans=-1;
        printf("Case %d: %d\n", cas, ans);
    }
    return 0;
}


分享到:
评论

相关推荐

    PC.rar_even parity _偶校验_校验和

    采用异步方式传送数据,偶校验,一位结束位,传输的数据传输速率为9600bit/s。每个数据帧包含10Byte信息,1Byte作为帧起始标志,8Byte数据,1Byte的校验和。 //-----------------------函数声明,变量定义-

    Verilgo实现的FPGA奇偶校验 fpga开发.pdf

    This Verilog code implements a parity check circuit that generates the odd and even parity bits based on the input data. The circuit uses a clock signal and a reset signal to generate the parity bits....

    tip linux串口调试工具 C语言源码 ARM开发工具

    -e even parity -o odd parity -n no parity (default) -c use clocal mode (no disconnect) -t translate 5 bit codes to ascii -x use software flow (xon/xoff) -r use hardware flow (rts/cts) -f pass ...

    基于STM32F103的移动底座与ROS通信,包括ROS串口节点、STM32串口收发

    9600 8bits 1stop even parity ROS 节点 ROS 节点文件名为 my_serial_node ,将源文件解压放置~/catkin_ws/src 目录下,回到 ~/catkin_ws 目录下进行编译,该节点需要使用 serial库 直接clone serial 至本地,并...

    Low Density Parity Check Codes

    ### 低密度奇偶校验码 (Low Density Parity Check Codes) #### 概述 低密度奇偶校验码(Low Density Parity Check Codes,简称LDPC码)是一种高效的线性错误校正码,最初由罗伯特·G·加拉格尔(Robert G. ...

    parity-wasm, 在 Rust 中,WebAssembly序列化/反序列化.zip

    parity-wasm, 在 Rust 中,WebAssembly序列化/反序列化 奇偶校验 wasm低级WebAssembly格式库。 文档文档 Rust WebAssembly格式序列化/反序列化添加到 Cargo.toml[dependencies]parity-wasm = "0.31

    Introduction to Risk Parity and Budgeting

    Risk parity then became a popular financial model of investment after the global financial crisis in 2008. Today, pension funds and institutional investors are using this approach in the development ...

    消息传递算法 和积算法 因子图 matlab源码

    通过构造因子图(Factor Graph)关于和积算法(Sum-Product Algorithm)的matlab源码,借此可实现消息传递算法(Message Propagation Algorithm,MPA)、LDPC编解码、卡尔曼滤波、隐性马尔可夫链(HMC)等应用

    C++串口操作的DCB设置说明.doc

    奇偶校验是为了检测数据传输中的错误,常见的奇偶校验方法有偶校验(EVENPARITY)、奇校验(ODDPARITY)、无奇偶校验(NOPARITY)等。 流控制设置 DCB结构体中有多个成员变量用于控制串口的流控制,例如...

    Low-Density Parity-Check Codes

    ### 低密度奇偶校验码(Low-Density Parity-Check Codes,简称LDPC码) #### 引言 在1963年,罗伯特·G·加勒格在其博士论文中首次提出了低密度奇偶校验码的概念。这篇论文不仅为通信工程领域带来了重大的突破,...

    usart.rar_parity space_the space of parity

    "usart.rar_parity space_the space of parity"这个标题暗示了我们讨论的是关于USART在AVR上的配置,特别是关于奇偶校验位的设置。 在串口通信中,数据通常以帧的形式传输,每个帧包括起始位、数据位、奇偶校验位和...

    low-density-parity-check

    低密度奇偶校验码(LDPC)是一种线性纠错码,由Robert Gallager在1960年代初期首次提出,并在21世纪初期得到了广泛的研究和发展。LDPC码因其优异的纠错性能和较低的实现复杂度,在数字通信领域得到了广泛应用,尤其...

    Modbus[Com4;Slave;Parity]+Oled+E2prom(测试通过).zip

    Parity]+Oled+E2prom(测试通过).zip"中,开发者利用STC8A单片机实现了一个Modbus从站,该从站具备了串口通信、奇偶校验功能,并通过OLED显示屏展示通讯参数,同时使用E2prom存储这些参数。 首先,STC8A系列是STC...

    geth&parity_console.zip

    geth v1.9.8 支持parity模块rpc版本 此版本直接拉取2019/12/08 V1.9.8版本代码编译的,添加parity的rpc模块支持。其余功能未做修改。 自编译参考我的博文: ...

    AMBA interface parity AHB APB AXI4-Stream v2_AXI_axi4-stream_ARM

    - AHB总线协议包括读写操作、突发传输、数据宽度可配置(通常32位或64位)以及错误处理机制,如奇偶校验(parity)。 2. **APB (Advanced Peripheral Bus)** - APB是针对低功耗和低带宽外设设计的接口,它可以与...

    RS-232-C端口实时监控软件的设计实现

    - **校验方式**:无校验(NOPARITY)、奇校验(ODDPARITY)、偶校验(EVENPARITY)。 为了提高软件的灵活性和适用性,可以预设多种参数组合供用户选择,并允许在程序运行过程中随时更改设置。为此,可以自定义一个串口...

    DVP 通信协议设定

    - **奇偶校验**:Even parity(或Odd/None parity)。 - **停止位**:1bit或2bits。 - **通讯缓冲区长度**:在6.0版本前为16个寄存器,在6.0版本后增加至100个寄存器。 - **SA/SX/SC系列**: - **通讯速率**:...

    Two-dimensional-parity-check.rar_parity check_二维奇偶校验_奇偶校验_奇偶校验码

    这个名为"Two-dimensional-parity-check.rar"的压缩包包含了关于该主题的详细研究,特别是利用MATLAB进行的实践测试。MATLAB是一种强大的数学计算和编程环境,非常适合于模拟和分析这种基于数学原理的纠错编码。 ...

    ANN.rar_ANN_ANN parity 4_ANN算法源代码_BP神经网络算法

    "ANN.rar_ANN_ANN parity 4_ANN算法源代码_BP神经网络算法" 这个标题表明,这是一个与人工神经网络(Artificial Neural Network,简称ANN)相关的压缩包,具体来说,是关于解决奇偶问题(parity problem)的一个实现...

Global site tag (gtag.js) - Google Analytics