ACdream区域赛指导赛之手速赛系列(6) A.
来源:互联网 发布:网络视频监控系统方案 编辑:程序博客网 时间:2024/06/05 22:49
A - Problem A
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
335 3 4 6 7 8 9 1 26 7 2 1 9 5 3 4 81 9 8 3 4 2 5 6 78 5 9 7 6 1 4 2 34 2 6 8 5 3 7 9 17 1 3 9 2 4 8 5 69 6 1 5 3 7 2 8 42 8 7 4 1 9 6 3 53 4 5 2 8 6 1 7 931 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 935 3 4 6 7 8 9 1 26 7 2 1 9 5 3 4 81 9 8 3 4 2 5 6 78 5 9 7 6 1 4 2 34 2 6 8 999 3 7 9 17 1 3 9 2 4 8 5 69 6 1 5 3 7 2 8 42 8 7 4 1 9 6 3 53 4 5 2 8 6 1 7 9
Sample Output
Case #1: YesCase #2: NoCase #3: No
解题思路:
本题大意是判断一个n^2 * n^2的矩阵是否满足每行元素属于1~n^2(且不相等)、
每列元素属于1~n^2(且不相等)、每个n*n子矩阵元素属于1~n^2(且不相等)。
直接暴力····最精彩的是最后一个判断子矩阵的时候(四层循环)····直接上代码····
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int a[1111][1111];int vis[1111];int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); int cas = 1; while(T--) { int n; scanf("%d",&n); int s = n * n; int len = n * n * n * n; for(int i = 0 ; i < s ; i ++) { for(int j = 0 ; j < s ; j ++) { scanf("%d",&a[i][j]); } } printf("Case #%d: ", cas++); int flag = 0; for(int i = 0 ; i < s ; i ++) { memset(vis , 0 , sizeof(vis)); for(int j = 0 ; j < s ; j ++) vis[a[i][j]] ++; for(int k = 1 ; k <= s ; k ++) { if(vis[k] != 1) { flag = 1; break; } } if(flag) break; } if(flag) { printf("No\n"); continue; } for(int j = 0 ; j < s ; j ++) { memset(vis , 0 , sizeof(vis)); for(int i = 0 ; i < s ; i ++) { vis[a[i][j]] ++; } for(int k = 1 ; k <= s ; k ++) { if(vis[k] != 1) { flag = 1; break; } } if(flag) break; } if(flag) { printf("No\n"); continue; } for(int i = 0 ; i < s ; i += n ) { for(int j = 0 ; j < s ; j += n) { memset(vis , 0 , sizeof(vis)); for(int k = i ; k < n + i; k ++) { for(int t = j ; t < n + j; t ++) vis[a[k][t]] ++; } for(int q = 1 ; q <= s; q ++) { if(vis[q] != 1) { flag = 1; break; } } if(flag) break; } if(flag) break; } if(flag) { printf("No"); continue; } printf("Yes\n"); }}
- ACdream区域赛指导赛之手速赛系列(6) A.
- ACdream区域赛指导赛之手速赛系列(6)
- ACdream区域赛指导赛之手速赛系列(2)
- ACdream区域赛指导赛之手速赛系列(4)题解
- ACdream区域赛指导赛之手速赛系列(4)
- ACdream区域赛指导赛之手速赛系列(5) 题解
- ACdream区域赛指导赛之手速赛系列(7)
- ACdream区域赛指导赛之手速赛系列(4) A Bad Horse
- ACdream区域赛指导赛之手速赛系列(5) 解题报告 A C D
- ACdream区域赛指导赛之手速赛系列(6) 解题报告
- ACdream区域赛指导赛之手速赛系列(4) C Captain Hammer
- ACdream区域赛指导赛之手速赛系列(4) E Tic-Tac-Toe-Tomek
- ACdream区域赛指导赛之专题赛系列(1)の数学专场
- ACdream 区域赛指导赛之专题赛系列(1)の数学专场 A - EOF女神的相反数 (反转2进制)
- 数论 A - 梦 -----acdream ACdream原创群赛(12)のBUAA选拔赛
- ACdream原创群赛(12)のBUAA选拔赛 A - 梦
- acdream A
- ACdream oj 1191 Dragon Maze(手速赛 A)
- 动态规划 之 最长上升序列
- android的drawable 和bitmap的效率对比测试
- C# 文字动态转成图片
- 人脸识别系统,分类学习
- JS事件冒泡问题的处理
- ACdream区域赛指导赛之手速赛系列(6) A.
- 在 cocos2d-x 3.0 中中文显示为乱码的问题
- hdu 2059(龟兔赛跑 dp)
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
- HDU 3395 Special Fish
- 二、Java类和对象
- z-index的一个非常重要的细节
- 迅雷IOS面试总结
- activeMQ无法启动