写的时候多打了个叹号... 坑了很久
#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;
}
分享到:
相关推荐
Digital Design Odd or Even Parity
采用异步方式传送数据,偶校验,一位结束位,传输的数据传输速率为9600bit/s。每个数据帧包含10Byte信息,1Byte作为帧起始标志,8Byte数据,1Byte的校验和。 //-----------------------函数声明,变量定义-
16-bit数的偶数奇偶校验及阶乘运算,用verilog写
Low Density Parity Check Codes Robert G. Gallager 1963
8-bit 的奇偶效验电路输入信号:data 输入 8-bit 数据;输出信号:odd 奇效验输出。当数据中有奇数个 1 时,输出 odd 为 1;even 偶效验输出。当数据中有偶数个 1 时,输出 even 为 1
geth v1.9.8 支持parity模块rpc版本 此版本直接拉取2019/12/08 V1.9.8版本代码编译的,添加parity的rpc模块支持。其余功能未做修改。 自编译参考我的博文: ...
Risk parity is a type of asset allocation strategy that has become increasingly popular in the aftermath of the global financial crisis
the proof for Parity is not in AC0
Risk parity is an advanced portfolio technique often used by hedge funds. It typically requires quantitative methodology which makes its allocations more advanced than simplified allocation strategies...
parity-wasm, 在 Rust 中,WebAssembly序列化/反序列化 奇偶校验 wasm低级WebAssembly格式库。 文档文档 Rust WebAssembly格式序列化/反序列化添加到 Cargo.toml[dependencies]parity-wasm = "0.31
LDPC译码的详细介绍过程,讲述LDPC译码的分类、各译码的实现过程
Risk parity is a type of asset allocation strategy that has become increasingly popular in the aftermath of the global financial crisis
AMBA interface parity AHB APB AXI4-Stream v2_AXI_axi4-stream_ARM总线_axi4_stream_axi4_源码.zip
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 ...
parity. The error rate of professional transcriptionists is 5.9% for the Switchboard portion of the data, in which newly acquainted pairs of people discuss an assigned topic, and 11.3% for the Call...
Risk parity is an advanced portfolio technique often used by hedge funds. It typically requires quantitative methodology which makes its allocations more advanced than simplified allocation strategies...
Galleger的博士论文,LDPC。做了整理
Risk parity is an advanced portfolio technique often used by hedge funds. It typically requires quantitative methodology which makes its allocations more advanced than simplified allocation strategies...
Risk parity is a type of asset allocation strategy that has become increasingly popular in the aftermath of the global financial crisis