ACdream区域赛指导赛之手速赛系列(6)

Problem Description

Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each column, each row, and all 9 non-overlapping 3x3 sub-matrices contain all of the digits from 1 through 9. Each 9x9 matrix is partially completed at the
start of game play and typically has a unique solution.

      

Given a completed N2×N2 Sudoku matrix, your task is to determine whether it is a valid solution.

A valid solution must satisfy the following criteria:

  • Each row contains each number from 1 to N2, once each.
  • Each column contains each number from 1 to N2, once each.
  • Divide the N2×N2 matrix into N2 non-overlapping
    N×N sub-matrices. Each sub-matrix contains each number from 1 to N2, once each.

You don‘t need to worry about the uniqueness of the problem. Just check if the given matrix is a valid solution.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow. Each test case starts with an integer N(3 ≤ N ≤ 6).

The next N2 lines describe a completed Sudoku solution, with each line contains exactly
N2 integers.

All input integers are positive and less than 1000.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and
y is "Yes" (quotes for clarity only) if it is a valid solution, or "No" (quotes for clarity only) if it is invalid.

Sample Input

3
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 999 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

Sample Output

Case #1: Yes
Case #2: No
Case #3: No
#include<iostream>
using namespace std;

int n;
int small[40][40];
int col[40][40];
int row[40][40];

int main()
{
    int T;
    cin>>T;
    int a;
    int k;
    for(int count = 0;count<T;count++)
    {
    	bool flag = false;
    	cin>>n;
    	memset(small,0,sizeof(small));
        memset(col,0,sizeof(col));
        memset(row,0,sizeof(row));
        for(int i=0;i<n*n;i++){
            for(int j=0;j<n*n;j++){
            	k = (i/n)*n+j/n;   //这里的规律总结出来很重要!!
    			cin>>a;
    			if(a<1||a>n*n){
                    flag=true;
                    continue;
                }
                // 对每行进行检查
                if(row[i][a]){
                    flag=true;
                }
                else row[i][a]=true;
                // 对每列进行检查
                if(col[j][a]){
                    flag=true;
                }
                else col[j][a]=true;
                // 对每个小的矩形块进行检查
                if(small[k][a]){
                    flag=true;
                }
                else {
                    small[k][a]=true;
                }
            }
        }
        if(!flag)printf("Case #%d: Yes\n",count);
        else printf("Case #%d: No\n",count);
    }
    return 0;
}
时间: 2024-10-23 08:32:49

ACdream区域赛指导赛之手速赛系列(6)的相关文章

ACdream区域赛指导赛之手速赛系列(5) 题解

A - Problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description The decimal numeral system is composed of ten digits, which we represent as "0123456789" (the digits in a system are

ACdream区域赛指导赛之手速赛系列(7)

A - Dragon Maze Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus 题目连接:     传送门 Problem Description You are the prince of Dragon Kingdom and your kingdom is in danger of running out of power. You must find

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)G——BFS——Cutting Figure

Description You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make i

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)D——数学——Triangles

Description 已知一个圆的圆周被  N 个点分成了 N 段等长圆弧,求任意取三个点,组成锐角三角形的个数. Input 多组数据. 每组数据一个N (N ≤  1000000). Output 对于每组数据,输出不同锐角三角形的个数. Sample Input 3 4 5 Sample Output 1 0 5大意:数学推导,分成奇数点偶数点讨论偶数时:只要两个相减就是答案奇数时同理:还有1ll*涨姿势用来变成long long 形式 #include<cstdio> #includ

HUST_ACdream区域赛指导赛之手速赛系列(1)(2)F——GCD+1ll——LCM Challenge

Description Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they do

快速切题 acdream手速赛(6)A-C

Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each colu

Acdream手速赛7

蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和出口坐标,要求从入口到出口的步数尽可能少,如果有多种方案,则要求获得的分数尽可能多,获得的分数为经过的方格的数字之和 思路: bfs求最小步数,每走一步更新一下走到这个格子的最大权值 #include <bits/stdc++.h> using namespace std; typedef lon

Java制作最难练手速游戏,Faker都坚持不了一分钟

想练手速,来啊,互相伤害啊 Java制作最难练手速游戏,目测Faker也坚持不了一分钟 制作思路:只靠Java实现.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java.Java. 字母模型应该是整个游戏的主角,因为整个游戏过程中都涉及到它的运动,比如坠落,消失,产生等,首先应该考虑字母随即出现的位置,在游戏中不断下落,计算下落的高

猫和老鼠 蓝桥杯/手速/暴力练习赛(暴力搜索)

猫和老鼠 蓝桥杯/手速/暴力练习赛 [题目描述] 猫和老鼠在10*10 的方格中运动,例如: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ..M......* ...*.*.... .*.*...... C=猫(CAT) M=老鼠(MOUSE) *=障碍物 .=空地 猫和老鼠每秒中走一格,如果在某一秒末他们在同一格中,我们称他们“相遇”. 注意,“对穿”是不算相遇的.猫和老鼠的移动方式相