题目链接:http://acm.uestc.edu.cn/#/problem/show/1226

题目大意就是构造一个行列和每个角的2*2都是1234的4*4矩阵。

用dfs暴力搜索,不过需要每一步进行判断是否已经出现了重复,如果最后再判断的话复杂度有点高。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#define LL long long using namespace std; char str[][];
int a[][];
bool vis[];
bool flag; bool judge(int x[][])
{
for (int i = ; i < ; ++i)
{
memset(vis, false, sizeof(vis));
for (int j = ; j < ; ++j)
{
if (!x[i][j]) continue;
if (vis[x[i][j]]) return false;
else vis[x[i][j]] = true;
}
}
for (int j = ; j < ; ++j)
{
memset(vis, false, sizeof(vis));
for (int i = ; i < ; ++i)
{
if (!x[i][j]) continue;
if (vis[x[i][j]]) return false;
else vis[x[i][j]] = true;
}
}
for (int i = ; i <= ; i += )
{
for (int j = ; j <= ; j += )
{
memset(vis, false, sizeof(vis));
for (int xx = ; xx <= ; xx++)
{
for (int yy = ; yy <= ; yy++)
{
if (!x[i+xx][j+yy]) continue;
if (vis[x[i+xx][j+yy]]) return false;
else vis[x[i+xx][j+yy]] = true;
}
}
}
}
return true;
} void input()
{
for (int i = ; i < ; ++i)
{
scanf("%s", str[i]);
for (int j = ; j < ; ++j)
{
if (str[i][j] == '*')
a[i][j] = ;
else
a[i][j] = str[i][j]-'';
}
}
} void dfs(int i, int j)
{
if (flag) return;
i += j/;
j %= ;
if (i == )
{
if (judge(a))
{
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; ++j)
printf("%d", a[i][j]);
printf("\n");
}
flag = true;
}
return;
}
if (!judge(a)) return;
if (!a[i][j])
{
for (int x = ; x <= ; ++x)
{
a[i][j] = x;
dfs(i, j+);
a[i][j] = ;
}
}
else dfs(i, j+);
} void work()
{
flag = false;
dfs(, );
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
printf("Case #%d:\n", times);
input();
work();
}
return ;
}

ACM学习历程—UESTC 1222 Sudoku(矩阵)(2015CCPC H)的更多相关文章

  1. ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1215 题目大意就是问一个2*2的矩阵能否通过旋转得到另一个. 代码: #include <iostre ...

  2. ACM学习历程—UESTC 1218 Pick The Sticks(动态规划)(2015CCPC D)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 题目大意就是求n根木棒能不能放进一个容器里,乍一看像01背包,但是容器的两端可以溢出容器,只要两端的木 ...

  3. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  4. ACM学习历程—UESTC 1226 Huatuo's Medicine(数学)(2015CCPC L)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. ...

  5. ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...

  6. ACM学习历程—HDU5667 Sequence(数论 && 矩阵乘法 && 快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=5667 这题的关键是处理指数,因为最后结果是a^t这种的,主要是如何计算t. 发现t是一个递推式,t(n) = c ...

  7. ACM学习历程—SNNUOJ1215 矩阵2(二分 && dfs)

    http://219.244.176.199/JudgeOnline/problem.php?id=1215 这是这次微软和百度实习面试的一道题,题目大意就是:有一个n*m的矩阵,已知它每一行都是不严 ...

  8. ACM学习历程—SNNUOJ1214 矩阵1(二分)

    题目链接:http://219.244.176.199/JudgeOnline/problem.php?id=1214 这是这次微软实习面试的一道题,题目大意就是:有一个n*m的矩阵,已知它每一行都是 ...

  9. ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)

    Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...

随机推荐

  1. lua(注册c库)

    #include <iostream> #include <string.h> extern "C" { #include "lua-5.2.2/ ...

  2. CAFFE学习笔记(二)Caffe_Example之测试mnist

    这一次的博客将接着上一次的内容,简单讲解一下如何使用训练后的网络lenet_iter_5000.caffemodel与lenet_iter_10000.caffemodel. 1.在网络训练完毕后,将 ...

  3. ResfulApi规范

    序号 方法 描述 1 GET 请求指定的页面信息,并返回实体主体. 2 HEAD 类似于get请求,只不过返回的响应中没有具体的内容,用于获取报头 3 POST 向指定资源提交数据进行处理请求(例如提 ...

  4. swift 一句代码补全tableView分割线

    1.swift实现分割线补全 swift一个大进步,只要设置tableView.separatorInset = UIEdgeInsets.zero即可补全分割线, 2.OC实现分割线补全 而在OC中 ...

  5. 在函数中如何获取 线程对象、线程唯一ID

    threading.current_thread() threading.current_thread().ident

  6. emmet缩写格式

    2016年5月30日 10:10 标准网页<!DOCTYPE html> <html lang="zh-CN"> <head> <meta ...

  7. java基础入门1到100的奇数求和

    /* Name:1-100所有奇数求和的程序 Power by Stuart Date:2015-4-23 */ public class DateTest01{ public static void ...

  8. (转)ubuntu 12.04搭建Adobe Flash Media Server服务

    破解版传送门:http://fms45.cuplayer.com/fms4download.html 福利:1462-5247-1705-7678-8379-5590 下载解压 cd进目录,./ins ...

  9. java 类中定义接口的调用方法

    public class Human { public interface MyAction { public void getPower(); } } public class Test{ publ ...

  10. 模仿jquery框架源码 -生长---跨域访问

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...