B3109 [cqoi2013]新数独 搜索dfs
就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了。
题干:
题目描述

输入格式
输出格式
样例输入
< > > < > <
v v ^ ^ v v ^ ^ ^
< < > < > <
^ ^ ^ v ^ ^ ^ v v
< < < < > >
> < > > > >
v ^ ^ ^ ^ v v v ^
> > > > < >
v v ^ v ^ v ^ v ^
> < < > > >
< < < < > <
v ^ v v v v ^ ^ v
< > > < < >
^ v v v ^ v ^ v v
< > < > < >
样例输出
4 9 1 7 3 6 5 2 8
2 3 7 8 1 5 6 4 9
5 6 8 2 4 9 7 3 1
9 1 3 6 5 4 8 7 2
8 5 4 9 7 2 1 6 3
7 2 6 3 8 1 9 5 4
3 4 9 5 6 8 2 1 7
1 8 5 4 2 7 3 9 6
6 7 2 1 9 3 4 8 5
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int n;
char o;
bool gx[][][][],h[][],l[][],g[][];
int a[][];
void dfs(int x,int y)
{
if(a[x][y])
{
if(x == && y == )
{
duke(i,,)
{
duke(j,,)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
else if(y == )
{
dfs(x + ,);
}
else
{
dfs(x,y + );
}
}
else
{
duke(i,,)
{
if(!h[x][i] && !l[y][i] && !g[(x - ) / * + (y - ) / + ][i] && (((a[x - ][y] > i) == gx[x - ][y][x][y]) || (x % == )) && ((y % == ) || ((a[x][y - ] > i) == gx[x][y - ][x][y])))
{
a[x][y] = i;
h[x][i] = true,
l[y][i] = true,
g[(x - ) / * + (y - ) / + ][i] = true;
dfs(x,y);
a[x][y] = ;
h[x][i] = false,
l[y][i] = false,
g[(x - ) / * + (y - ) / + ][i] = false;
}
}
} }
int main()
{
duke(i,,)
{
duke(j,,)
{
if(j % == )
{
duke(k,,)
{
cin>>o;
if(o == 'v')
gx[(i - ) * + j / ][k][(i - ) * + j / + ][k] = true;
}
}
else
{
duke(k,,)
{
cin>>o;
if(o == '>')
gx[(i - ) * + (j - ) / + ][(k - ) / * + (k - ) % + ][(i - ) * + (j - ) / + ][(k - ) / * + (k - ) % + ] = true;
}
}
}
}
dfs(,);
return ;
}
B3109 [cqoi2013]新数独 搜索dfs的更多相关文章
- 3109. [CQOI2013]新数独【DFS】
Description Input 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第偶数行包含上下方向的符号(^和v). Output 输出包含9行,每行 ...
- bzoj 3109: [cqoi2013]新数独【dfs】
按3x3的小块dfs,填数的时候直接满足所有条件即可 #include<iostream> #include<cstdio> #include<cstring> u ...
- 【搜索】bzoj3109 [cqoi2013]新数独
搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...
- CQOI2013 新数独
传送门 这道题也是很暴力的搜索啊…… 因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法. 这题最恶心的是读入.现学了一招判断点在哪个块 ...
- bzoj 3109: [cqoi2013]新数独
#include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...
- BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...
- bzoj3109【CQOI2013】新数独
3109: [cqoi2013]新数独 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 365 Solved: 229 [Submit][Statu ...
- 记忆化搜索(DFS+DP) URAL 1501 Sense of Beauty
题目传送门 /* 题意:给了两堆牌,每次从首部取出一张牌,按颜色分配到两个新堆,分配过程两新堆的总数差不大于1 记忆化搜索(DFS+DP):我们思考如果我们将连续的两个操作看成一个集体操作,那么这个操 ...
- 用深度优先搜索(DFS)解决多数图论问题
前言 本文大概是作者对图论大部分内容的分析和总结吧,\(\text{OI}\)和语文能力有限,且部分说明和推导可能有错误和不足,希望能指出. 创作本文是为了提供彼此学习交流的机会,也算是作者在忙碌的中 ...
随机推荐
- JS——行内式注册事件
html中行内调用function的时候,是通过window调用的function,所以打印this等于打印window,所以在使用行内注册事件时务必传入参数this <!DOCTYPE htm ...
- css 众妙之门 学习笔记
伪类: 结构伪类: :empty :only-child :before :after :active :hover :focus :link :visited :first-child :last- ...
- CorelDRAW快速制作抖音幻影图像效果
本教程讲解非常受欢迎的幻影图像效果(Anaglyph 3d),也叫图像分色立体效果,这其中我们要用到CorelDRAW中的透明度工具. 在开始实施Anaglyph效应之前,应当知道,Anaglyph ...
- 2019 支付宝App支付 --- PHP
SDK下载:https://docs.open.alipay.com/54/106370/;联系客服:https://cschannel.alipay.com/newPortal.htm?scene= ...
- demo__webpack
webpack 中使用的包更新非常频繁,使用方式可能很快就会改变,解决方式 看webapck文档 和 包的使用文档 看包的源码 其他... 环境 win10 + webstorm 2019.1.3 + ...
- Python 索引切片
#负数开头,只有比负数大才有数据 num = [1,2,3,4,5,6,7,8,9,10] print(num[-5:5]) num = [1,2,3,4,5,6,7,8,9,10] print(nu ...
- 配置yum仓库和rpm包
作业一: 1) 开启Linux系统前添加一块大小为15G的SCSI硬盘 2) 开启系统,右击桌面,打开终端 3) 为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划分1个逻辑分 ...
- 洛谷 1486 郁闷的出纳员【Treap】
[题意概述] 要求维护一个序列支持以下操作: 1,插入元素x: 2,把序列的所有元素加上x: 3,把序列的所有元素减去x,同时低于一个给定的下限的元素马上被删除: 4,询问序列中第k大的元素. [题解 ...
- BZOJ 1452 Count 【模板】二维树状数组
对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...
- 为什么有些图像在显示前要除以255?(zhuan)
imshow是用来显示图片的,如 >> I = imread('moon.tif'); >> figure,imshow(I); 而有时为了数据处理,要把读取的图片信息转化为更 ...