题目链接: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. Linux - SVN的基本操作

    SVN的基本操作 本文地址: http://blog.csdn.net/caroline_wendy $ svn diff //显示改动 $ post-review --summary="b ...

  2. random随机模块,time时间模块

    random /随机模块: 作用: 在某个范围内取到每一个值得概率是相通的. 一.随机小数 random.random() import random print(random.random())  ...

  3. Jmeter + Ant + Jenkins 接口/性能测试,持续集成环境搭建

    1. 安装Jmeter.jdk Jmeter 3.3版本 :<http://note.youdao.com/noteshare?id=5e3fd287db24d08386207a7de22d26 ...

  4. EasyNVR无插件直播服务器软件览器低延时播放监控摄像头视频(EasyNVR播放FLV视频流)

    背景描述 EasyNVR的使用者应该都是清楚的了解到,EasyNVR一个强大的功能就是可以进行全平台的无插件直播.主要原因在于rtsp协议的视频流(默认是需要插件才可以播放的)经由EasyNVR处理可 ...

  5. java List的相关工具类

    1. <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</ar ...

  6. xlrd python excel

     xlrd python excel

  7. HDU - 5695 Gym Class 【拓扑排序】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5695 思路 给定一些关系 进行拓扑排序 但是有一个要求 对于哪些没有确切的位置的点 要按照ID大小 I ...

  8. HDU - 2701 Lampyridae Teleportae 【模拟】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2701 题意 有一个萤火虫会闪现 一个人 也会闪现 给出 这个人的起始位置 和他能够闪现的距离 然后依次 ...

  9. ZOJ - 3705 Applications 【模拟】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3705 题意 给出N个队员 然后一个教练要从中选择 M名队员 要选 ...

  10. Android AbsoluteLayout绝对布局

    绝对布局也叫坐标布局,指定元素的绝对位置,因为适应性很差,一般很少用到.可以使用RelativeLayout替代. 常用属性: android:layout_x --------组件x坐标 andro ...