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. 使用PowerShell为SSAS Role添加Membership

    PowerShell, SSAS, Role, Membership 上篇随笔使用PowerShell创建SSAS Role贴出了如何使用PowerShell批量创建Role,由于个人项目需求,创建R ...

  2. C# OO(初级思想)。

    继承,多态,封装 在C#中,为了能够合理描述自然界的规律,面向对象的编程引入了继承的概念,是面向对象编程中最重要的概念之一,定义了如何根据现有的类创建新类的过程. 继承:一个类派生出来的子类具有这个类 ...

  3. Cheatsheet: 2017 06.01 ~ 06.30

    .NET Porting a .NET Framework library to .NET Core Performance Improvements in .NET Core High-perfor ...

  4. 十七、ThreadPoolExecutor线程池

    一.简介 executor接口 executor接口在JDK的java.util.concurrent包下,它只有一个抽象方法: void execute(Runnable command); 这意味 ...

  5. hdu 2049 考新郎

    假设一共有N对新婚夫妇,其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能. 和之前那道题一样,是错排,但是要乘上排列数. 选对的人有C(N,M)个组合,将它们排除掉,剩下的人就是错排了 #in ...

  6. Java 基础:数组

    一.数组声明: int[] x; int x[]; 在Java中一般使用前者,机把int[]看做一个类型,C++中只能后者 二.数组初始化: 直接提供值: int[] x = {1, 3, 4}; i ...

  7. 转:问题解决:The project cannot be built until build path errors are resolved

    转自:http://blog.csdn.net/marty_zhu/article/details/2566299 今天在eclipse里遇到这个问题,之前也遇到过,不过,通过clean一下项目,或者 ...

  8. 移动目标在三维GIS中的实现方法

    对于基于ArcGIS Runtime的应用程序,其实现方法比较简单,可以直接更新图形的Geometry属性,即可实现位置的移动: private void AddGraphics() { var gl ...

  9. 解决nexus3报Cannot open local storage 'component' with mode=rw的异常问题

    起因:正常使用的公司Maven.Docker私有仓库,突然镜像不能推送,返回getsockopt: connection refused,用docker客户端登录也是返回同样的错误,查看nexus3日 ...

  10. 在AndroidStudio中数据存储第三方数据管理Bmob的使用

    ---恢复内容开始--- 在日常写代码的过程中我们比较痛苦的就是数据库的建立和使用,那么今天来介绍一下一个第三方的数据管理平台Bmonb. 一.我们首先进入Bmob的官网创建一个账号 Bome官网网址 ...