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. Quartz大致介绍(一)

    1. 介绍 Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,是完全由java开发的一个开源的任务日程管理系统,“任务进度管理器”就是一个在预先确定(被纳 ...

  2. ubuntu关机重启命令

    重启命令 :     1.reboot     2.shutdown -r now 立刻重启    3.shutdown -r 10 过10分钟自动重启    4.shutdown -r 20:35 ...

  3. Oracle SQL developer 连接 MySQL 数据库安装配置

    1. 下载 JDBC driver for MySQL 下载链接: https://dev.mysql.com/downloads/connector/j/ 下载成功后,解压缩,得到 mysql jd ...

  4. golang 记录函数执行耗时的一个简单方法。

    先写一个公共函数, 比如在 common 包下有这么一个方法: // 写超时警告日志 通用方法 func TimeoutWarning(tag, detailed string, start time ...

  5. 【说文解字】Unix与Linux

    历史 Unix操作系统是由Ken Thompson和Dennis Ritchie于1969-1970年发明. 它的部分技术来源可以追溯到Multics工程,后者因为过于庞大复杂而失败. 研究人员吸取教 ...

  6. MyBatis学习(一)---配置文件,Mapper接口和动态SQL

    MyBatis MyBatis官方学习网站 http://www.mybatis.org/mybatis-3/zh/index.html 为什么需要MyBatis? Jdbc操作数据库的不足之处 1. ...

  7. BZOJ4513: [Sdoi2016]储能表(数位dp)

    题意 题目链接 Sol 一点思路都没有,只会暴力,没想到标算是数位dp??Orz 首先答案可以分成两部分来统计 设 \[ f_{i,j}= \begin{aligned} i\oplus j & ...

  8. easy canvas shape with react antdesign 简单的canvas图形in antd & react

    //show: //code: import React from "react" import {findDOMNode} from 'react-dom' import { B ...

  9. drupal7 获取当前使用的主题的名称

    直接引用全局变量就行: 参考: 代码测试: global $theme, $theme_key; echo $theme; echo '<br>'; echo $theme_key; 结果 ...

  10. antd-mobile的按需加载

    "babel": { "presets": [ "react-app" ] } 主要问题是 依赖项的版本问题 以及 配置问题 新添加的con ...