Description

Input

输入一共15行,包含一个新数独的实例。第奇数行包含左右方向的符号(<和>),第偶数行包含上下方向的符号(^和v)。
 

Output

输出包含9行,每行9个1~9的数字,以单个空格隔开。输入保证解惟一。

Sample Input

< > > < > <
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
< > < > < >

Sample Output

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<cstring>
#include<cstdio>
#define id(x,y) (x-1)*9+y
using namespace std;
int Relation[][],ans[][],maxn;
int dx[]= {,,-},dy[]= {,-,};
bool row[][],column[][],square[][][],flag;
char st[]; void Dfs(int x,int y)
{
maxn=max(x,maxn);
if (x== && y==)
{
flag=true;
for (int i=; i<=; ++i)
{
for (int j=; j<=; ++j)
printf("%d ",ans[i][j]);
printf("%d\n",ans[i][]);
}
return;
}
int down=,up=;
for (int i=; i<=; ++i)
{
int xx=x+dx[i],yy=y+dy[i];
if (xx< || xx> || yy< || yy> || ans[xx][yy]==) continue;
if ( Relation[id(x,y)][id(xx,yy)] == ) down=max(down,ans[xx][yy]+);
if ( Relation[id(x,y)][id(xx,yy)] == ) up=min(up,ans[xx][yy]-);
}
for (int i=down; i<=up; ++i)
if (!row[x][i] && !column[y][i] && !square[(x-)/][(y-)/][i])
{
ans[x][y]=i;
row[x][i]=column[y][i]=square[(x-)/][(y-)/][i]=true;
if (y==) Dfs(x+,);
else Dfs(x,y+);
ans[x][y]=;
row[x][i]=column[y][i]=square[(x-)/][(y-)/][i]=false; if (flag) return;
}
} int main()
{
memset(Relation,-,sizeof(Relation));
for (int i=; i<=; ++i)
if (i%==(^(i>= && i<=)))
{
for (int j=; j<=; ++j)
for (int k=; k<=; ++k)
{
char opt=getchar();
while (opt!='>' && opt!='<') opt=getchar();
if (opt=='>')
{
Relation[(j-)*+k+(i/+(i>))*][(j-)*+k+(i/+(i>))*+]=;
Relation[(j-)*+k+(i/+(i>))*+][(j-)*+k+(i/+(i>))*]=;
}
else
{
Relation[(j-)*+k+(i/+(i>))*+][(j-)*+k+(i/+(i>))*]=;
Relation[(j-)*+k+(i/+(i>))*][(j-)*+k+(i/+(i>))*+]=;
}
} }
else
{
for (int j=; j<=; ++j)
{
char opt=getchar();
while (opt!='^' && opt!='v') opt=getchar();
if (opt=='v')
{
Relation[id(i/+(i>=),j)][id(i/+(i>=)+,j)]=;
Relation[id(i/+(i>=)+,j)][id(i/+(i>=),j)]=;
}
else
{
Relation[id(i/+(i>=)+,j)][id(i/+(i>=),j)]=;
Relation[id(i/+(i>=),j)][id(i/+(i>=)+,j)]=;
}
}
}
Dfs(,);
}

3109. [CQOI2013]新数独【DFS】的更多相关文章

  1. bzoj 3109: [cqoi2013]新数独【dfs】

    按3x3的小块dfs,填数的时候直接满足所有条件即可 #include<iostream> #include<cstdio> #include<cstring> u ...

  2. bzoj 3109: [cqoi2013]新数独

    #include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...

  3. B3109 [cqoi2013]新数独 搜索dfs

    就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...

  4. BZOJ3109: [cqoi2013]新数独

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...

  5. CQOI2013 新数独

    传送门 这道题也是很暴力的搜索啊…… 因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法. 这题最恶心的是读入.现学了一招判断点在哪个块 ...

  6. 【搜索】bzoj3109 [cqoi2013]新数独

    搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...

  7. bzoj3109【CQOI2013】新数独

    3109: [cqoi2013]新数独 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 365  Solved: 229 [Submit][Statu ...

  8. BZOJ3105: [cqoi2013]新Nim游戏 博弈论+线性基

    一个原来写的题. 既然最后是nim游戏,且玩家是先手,则希望第二回合结束后是一个异或和不为0的局面,这样才能必胜. 所以思考一下我们要在第一回合留下线性基 然后就是求线性基,因为要取走的最少,所以排一 ...

  9. BZOJ3105: [cqoi2013]新Nim游戏

    题解: 线性基?类似于向量上的基底. 此题题解戳这里:http://blog.csdn.net/wyfcyx_forever/article/details/39477673 代码: #include ...

随机推荐

  1. 使用AngularJS 添加行修改、删除表格数据

    https://blog.csdn.net/xin_x1n/article/details/53070144 <html xmlns="http://www.w3.org/1999/x ...

  2. [转] 如何应用设计模式设计你的足球引擎(一和二)----Design Football Game(Part I and II)

    原文地址: http://www.codeproject.com/KB/architecture/applyingpatterns.aspx 作者:An 'OOP' Madhusudanan 译者:赖 ...

  3. LeetCode刷题第一天

    1 . 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用 ...

  4. JSP9大内置对象

    JSP9大内置对象 JSP9个内置对象:out对象 用于输出各种数据reuest对象 封装了来自客户端的各种信息response对象 封装了服务器的响应信息exception对象 封装了程序运行过程中 ...

  5. Spring入门(三)— AOP注解、jdbc模板、事务

    一.AOP注解开发 导入jar包 aop联盟包. aspectJ实现包 . spring-aop-xxx.jar . spring-aspect-xxx.jar 导入约束 aop约束 托管扩展类和被扩 ...

  6. libevent学习笔记 —— 牛刀小试:简易的服务器

    回想起之前自己用纯c手动写epoll循环,libevent用起来还真是很快捷啊!重写了之前学习的时候的一个例子,分别用纯c与libevent来实现.嗯,为了方便对比一下,就一个文件写到黑了. 纯c版: ...

  7. bsgs(Baby Steps Giant Steps)算法

    BSGS算法(Baby Steps Giant Steps算法,大步小步算法,北上广深算法,拔山盖世算法) 适用问题 对于式子: $$x^y=z(mod_p)$$ 已知x,z,p,p为质数: 求解一个 ...

  8. 手机浏览器的User-Agent汇总

    手机浏览器的User-Agent汇总 之前介绍的 更简洁的方式修改Chrome的User Agent,轻松体验移动版网络这种简洁的方法好像只适用于Chrome, Chrome不只是浏览界面简洁,对应的 ...

  9. Myeclipse中设置jsp页面的默认编码格式

    在MyEclispe中创建Jsp页面,Jsp页面的默认编码是“ISO-8859-1”,如下图所示: 在这种编码下编写中文是没有办法保存Jsp页面的,会出现如下的错误提示: 因此可以设置Jsp默认的编码 ...

  10. Flume -- Transfer one type of source to another type

    Source within Flume is a kind of Server for outside client. Sink within Flume is a kind of client fo ...