3109. [CQOI2013]新数独【DFS】
Description
.jpg)
Input
Output
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】的更多相关文章
- bzoj 3109: [cqoi2013]新数独【dfs】
按3x3的小块dfs,填数的时候直接满足所有条件即可 #include<iostream> #include<cstdio> #include<cstring> u ...
- bzoj 3109: [cqoi2013]新数独
#include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...
- B3109 [cqoi2013]新数独 搜索dfs
就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...
- BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...
- CQOI2013 新数独
传送门 这道题也是很暴力的搜索啊…… 因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法. 这题最恶心的是读入.现学了一招判断点在哪个块 ...
- 【搜索】bzoj3109 [cqoi2013]新数独
搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...
- bzoj3109【CQOI2013】新数独
3109: [cqoi2013]新数独 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 365 Solved: 229 [Submit][Statu ...
- BZOJ3105: [cqoi2013]新Nim游戏 博弈论+线性基
一个原来写的题. 既然最后是nim游戏,且玩家是先手,则希望第二回合结束后是一个异或和不为0的局面,这样才能必胜. 所以思考一下我们要在第一回合留下线性基 然后就是求线性基,因为要取走的最少,所以排一 ...
- BZOJ3105: [cqoi2013]新Nim游戏
题解: 线性基?类似于向量上的基底. 此题题解戳这里:http://blog.csdn.net/wyfcyx_forever/article/details/39477673 代码: #include ...
随机推荐
- JavaScript ES6 promiss的理解。
本着互联网的分享精神,我将我对promise的理解分享给大家. JavaScript ES6的promise方法主要应用在处理异步函数返回的结果,注意他不是将异步函数转换为同步函数,而是等异步函数有结 ...
- unity项目git管理
Unity设置 (关键) Edit -> Project Settings -> Editor -> Version Control Mode 开启 Visible Meta Fil ...
- php常用的时间函数
测试环境:php5.3.29 unix时间戳(从Unix 纪元(January 1 1970 00:00:00 GMT)到给定时间的秒数.).以下简称时间戳. 设置默认时区 date_default_ ...
- CodeForces 598A(水)
还是要注意int和long long的范围,以及double型的问题 pow函数经常会报一个double型的错,参考这篇文章 http://blog.csdn.net/lawrencesgj/arti ...
- 30个优秀的chrome网页设计开发插件
BuiltWith Resolution Test colorPicker Palette for Chrome Chrome Sniffer JS Library Detector Google F ...
- <!DOCTYPE> 标签是什么
DOCTYPE 标签,是html文档的类型声明(document type declaration,所谓声明,也就是宣称我他妈是谁),用来告诉浏览器,使用什么样的文档类型定义(Document Typ ...
- 命令行下运行 java someClass.class出现 “错误:找不到或无法加载主类someClass ” 的解决方案
假设在C:\Java\code\目录下建立了如下 Test.java文件: package code; public class Test { public static void main(Stri ...
- Linux基础入门之网络属性配置
Linux基础入门之网络属性配置 摘要 Linux网络属性配置,最根本的就是ip和子网掩码(netmask),子网掩码是用来让本地主机来判断通信目标是否是本地网络内主机的,从而采取不同的通信机制. L ...
- 在SQL service或Oracle中将数字转换成有千位符号
1.在SQL service中的写法: --Function主体 CREATE FUNCTION [dbo].[FnMoneyStyle](@Number )) RETURNS VARCHAR() A ...
- javascript之 原生document.querySelector和querySelectorAll方法
querySelector和querySelectorAll是W3C提供的新的查询接口,其主要特点如下: 1.querySelector只返回匹配的第一个元素,如果没有匹配项,返回null. 2.q ...