Codeforce961C(暴力)

本文介绍了一个关于修复2*nX2*n大小的混乱棋盘的问题。一个完整的棋盘被分为四个n*n大小的部分,颜色分布混乱。文章探讨了如何重新排列这些部分并更改最少数量的方格颜色以恢复棋盘原有的黑白相间模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Chessboard

Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what’s even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being black and 0 being white.
Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2n by 2n. You are allowed to move pieces but not allowed to rotate or flip them.
Input
The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board.
Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.
Output
Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.

题意:有一个2*n X 2*n大小的棋盘,棋盘上的颜色有两种它们分别用1和0表示,它们的位置相互交错。现在有一个棋盘分裂为4个n*n大小的块,并且上面的颜色已经乱了,要求你把这些块拼在一起,要求求出使棋盘颜色符合要求所需改颜色的次数最少是多少。
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000000
using namespace std;
typedef long long ll;
const int MAXN=1e9+10;
const int MAX=1e5+10;
const double eps=1e-6;

int n;
char s[5][110][110];

int main(){
    #ifdef ONLINE_JUDGE
    #else
    freopen("in.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif

    cin>>n;
    for(int k=1;k<=4;k++)
        for(int i=0;i<n;i++)
                scanf("%s",&s[k][i]);
    int ans=100000;
    for(int k=1;k<=4;k++){
        for(int h=k+1;h<=4;h++){
            int y,x;
            x=y=0;
            for(int i=1;i<=4;i++)
                if(i!=h&&i!=k){
                    if(!x)  x=i;
                    else    y=i;
                }
            int temp=0;
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if((i%2==1&&j%2==1)||(i%2==0&&j%2==0)){
                        if(s[k][i][j]!='1')   temp++;
                        if(s[h][i][j]!='1')   temp++;
                        if(s[x][i][j]!='0')   temp++;
                        if(s[y][i][j]!='0')   temp++;

                    }
                    else{
                        if(s[k][i][j]!='0')   temp++;
                        if(s[h][i][j]!='0')   temp++;
                        if(s[x][i][j]!='1')   temp++;
                        if(s[y][i][j]!='1')   temp++;
                    }
                }
            }
            ans=min(ans,temp);
        }
    }
    cout<<ans<<endl;

    return 0;
}
### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值