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. 对自写的Asp.Net分页控件的应用方式(异步无刷新分页)

    前台代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" co ...

  2. [javaSE] 集合框架(Map概述)

    Map集合,将key对象映射到value对象 三个主要的子类:Hashtable,HashMap,TreeMap Hashtable:底层是哈希表数据结构,不允许使用null值,线程同步 HashMa ...

  3. 利用QVOD架设流媒体服务器/电影服务器/vod服务器

    电影服务器一点也不稀罕,是的我们见的太多了,但是大家有没有想过自己也能架一个这样的服务器? 当然现在架一个电影服务器不切实际,去年吵的闹哄哄的“视听许可证”想必大家有所耳闻,再加上电影对服务器的要求一 ...

  4. java线程总结2--wait/notify(all)/sleep以及中断概念

    上一篇关于线程的博客简单梳理了一下多线程的一些基本概念,今天这篇博客再进行多线程编程中一些核心的方法进行简单的梳理和总结,主要是wait,sleep和notify方法以及中断的概念 一.中断概念. 在 ...

  5. 动态页面技术之JSP

    1.什么是JSP技术 JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Microsystems公司倡导.许多公司参与一起 ...

  6. ArcGIS中的坐标系统定义与投影转换

    坐标系统是GIS数据重要的数学基础,用于表示地理要素.图像和观测结果的参照系统,坐标系统的定义能够保证地理数据在软件中正确的显示其位置.方向和距离,缺少坐标系统的GIS数据是不完善的,因此在ArcGI ...

  7. BottomNavigationView结合ViewPager

    BottomNavigationView是Google推出的底部导航栏组件,在没有这些底部导航组件之前,Android开发者多使用的是RadioGroup,在上一个项目开发中我们使用了Google的B ...

  8. 本地调试接口返回信息不对 以及 jar冲突问题

    今天下午在本地调试的时候碰到个很奇怪的问题:服务调用接口,返回的明明是有数据的,然后通过gson转换对象后,对象里面并没有自己想要的数据.看了代码什么的都没有问题.思考到底是哪里出了问题,想了半天想到 ...

  9. c# 调用 c dll 例子

    // case 1 传递 int* ///////////////////////////////////////////// extern “C” __declspec(dllexport) int ...

  10. 初识WCF3

    http://www.cnblogs.com/xiangchangdong/p/3924030.html 第三篇 在IIS中寄宿服务 通过前两篇的学习,我们了解了如何搭建一个最简单的WCF通信模型,包 ...