Codeforces Round #634 D. Anti-Sudoku(构造/水)
Posted lipoicyclic
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #634 D. Anti-Sudoku(构造/水)相关的知识,希望对你有一定的参考价值。
题目描述
You are given a correct solution of the sudoku puzzle. If you don‘t know what is the sudoku, you can read about it here.
The picture showing the correct sudoku solution:
Blocks are bordered with bold black color.
Your task is to change at most 9 9 9 elements of this field (i.e. choose some 1≤i,j≤9 1 le i, j le 9 1≤i,j≤9 and change the number at the position (i,j) (i, j) (i,j) to any other number in range [1;9] [1; 9] [1;9] ) to make it anti-sudoku. The anti-sudoku is the 9×9 9 imes 9 9×9 field, in which:
- Any number in this field is in range [1;9] [1; 9] [1;9] ;
- each row contains at least two equal elements;
- each column contains at least two equal elements;
- each 3×3 3 imes 3 3×3 block (you can read what is the block in the link above) contains at least two equal elements.
It is guaranteed that the answer exists.
You have to answer t t t independent test cases.
输入格式
The first line of the input contains one integer t t t ( 1≤t≤104 1 le t le 10^4 1≤t≤104 ) — the number of test cases. Then t t t test cases follow.
Each test case consists of 9 9 9 lines, each line consists of 9 9 9 characters from 1 1 1 to 9 9 9 without any whitespaces — the correct solution of the sudoku puzzle.
输出格式
For each test case, print the answer — the initial field with at most 9 9 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
输入输出样例
1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563
154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
一开始构造麻烦了。。其实对于其中一个数x,把所有数变成x+1(9的话变成1)即可。因为每一行,每一列,每相邻九格里一定有一个x,把它+1一定会和另一个数重复,满足要求。
代码瞎邒写的,切勿参考。
#include <bits/stdc++.h> using namespace std; char a[11][11]; int main() { int t; cin>>t; getchar(); while(t--) { int i,j; for(i=0;i<9;i++) { for(j=0;j<9;j++) { scanf("%c",&a[i][j]); } getchar(); } for(i=0;i<9;i++) { int j; switch(i) { case 0: j=0; break; case 1: j=4; break; case 2: j=8; break; case 3: j=1; break; case 4: j=5; break; case 5: j=6; break; case 6: j=2; break; case 7: j=3; break; case 8: j=7; break; } if(a[i][j]!=‘9‘)a[i][j]=(int)(a[i][j]-‘0‘+1)+‘0‘; else a[i][j]=‘1‘; } for(i=0;i<=8;i++) { for(j=0;j<=8;j++) { printf("%c",a[i][j]); } cout<<endl; } } //0 0 0 4 0 8 //4 0 4 4 0 8 //8 0 8 4 8 8 return 0; }
以上是关于Codeforces Round #634 D. Anti-Sudoku(构造/水)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #634 (Div. 3) 补题
Codeforces Round #634 (Div. 3)
Codeforces Round #634 (Div. 3)
Educational Codeforces Round 26 D. Round Subset 动态规划