传送门

这道题也是很暴力的搜索啊……

因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法。

这题最恶心的是读入。现学了一招判断点在哪个块内,用lim[g][i][j],表示在g宫内i和j这两个格子的大小关系,处理还是相当复杂的(代码里有),之后就没什么要注意的,全是爆搜。

最后这个爆搜还会T两个点,要开O2.我也想不到有什么更好的优化了……

看一下代码。

// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#define rep(i,a,n) for(int i = a;i <= n;i++)
#define per(i,n,a) for(int i = n;i >= a;i--)
#define enter putchar('\n') using namespace std;
typedef long long ll;
const int M = ;
const int mod = 1e9 + ; int read()
{
int ans = ,op = ;
char ch = getchar();
while(ch < '' || ch > '')
{
if(ch == '-') op = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ans *= ;
ans += ch - '';
ch = getchar();
}
return ans * op;
} int num[][],hcnt,lcnt,px,py;
int lim[][][],vish[][],visl[][],visg[][];
char s; void print()
{
rep(i,,)
{
rep(j,,) printf("%d ",num[i][j]);enter;
}
} bool pd(int g,int pos,int k)
{
rep(j,,)
{
int dx = g / * + (j - ) / + ,dy = g % * + (j - ) % + ;
if(lim[g][pos][j] == && num[dx][dy] && k < num[dx][dy]) return ;
if(lim[g][pos][j] == && num[dx][dy] && k > num[dx][dy]) return ;
}
return ;
} void buildh(int i,int k)
{
rep(j,,)
{
int g = (i - ) * + ((j - ) >> );
int pos = ((k - ) >> ) * + ((j - ) & ) + ;
cin >> s;
lim[g][pos][pos+] = (s == '>') ? : ;
lim[g][pos+][pos] = (s == '>') ? : ;
}
} void buildl(int i,int k)
{
rep(j,,)
{
int g = (i - ) * + (j - ) / ;
int pos = ((k-) >> ) * + (j - ) % + ;
cin >> s;
lim[g][pos][pos+] = (s == 'v') ? : ;
lim[g][pos+][pos] = (s == 'v') ? : ;
}
} void build()
{
rep(i,,)
rep(k,,)
(k & ) ? buildh(i,k) : buildl(i,k);
} void dfs(int x,int y)
{
int g = ((x - ) / ) * + (y - ) / ;
int pos = (x - ) % * + (y - ) % + ;
rep(k,,)
{
if(vish[x][k] || visl[y][k] || visg[g][k]) continue;
if(!pd(g,pos,k)) continue;
vish[x][k] = visl[y][k] = visg[g][k] = ,num[x][y] = k;
//print();
if(x == && y == ) print(),exit();
else (y == ) ? dfs(x+,) : dfs(x,y+);
vish[x][k] = visl[y][k] = visg[g][k] = ,num[x][y] = ;
}
} int main()
{
build();
/*rep(i,1,9)
{
rep(j,1,9)
{
printf("%d ",lim[1][i][j]);
}
enter;
}*/
dfs(,);
return ;
}

CQOI2013 新数独的更多相关文章

  1. 3109. [CQOI2013]新数独【DFS】

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

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

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

  3. bzoj 3109: [cqoi2013]新数独

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

  4. BZOJ3109: [cqoi2013]新数独

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

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

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

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

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

  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. shell高级-----初识sed和gawk

    sed编辑器 sed说明 sed是Linux下一款功能强大的非交互流式文本编辑器,可以对文本文件进行增.删.改.查等操作,支持按行.按字段.按正则匹配文本内容,灵活方便,特别适合于大文件的编辑. 替换 ...

  2. Spring实战Day6

    3.4 bean的作用域 Spring中bean的作用域 单例(Singleton):在整个应用中,只创建bean的一个实例. 原型(Prototype):每次注入或者通过Spring应用上下文获取的 ...

  3. Deep learning网络调参技巧

    参数初始化 下面几种方式,随便选一个,结果基本都差不多.但是一定要做.否则可能会减慢收敛速度,影响收敛结果,甚至造成Nan等一系列问题.n_in为网络的输入大小,n_out为网络的输出大小,n为n_i ...

  4. [Unit Testing] Fundamentals of Testing in Javascript

    In this lesson, we’ll get the most fundamental understanding of what an automated test is in JavaScr ...

  5. SODBASE CEP学习(四)续:类SQL语言EPL与Storm或jStorm集成-使用分布式缓存

    流式计算在一些情况下会用到分布式缓存,从而实现(1)想把统计或计算结果保存在分布缓存中.供其他模块或其他系统调用. (2)某一滑动时间窗体上计数.比如实时统计1小时每一个Cookie的訪问量.实时统计 ...

  6. Go与C语言的互操作 cgo

    http://tonybai.com/2012/09/26/interoperability-between-go-and-c/ // foo.h int count; void foo(); //f ...

  7. 【转载】Socket通讯原理以及TCP、IP三次握手机制分析

    要写网络程序就必须用Socket,这是程序员都知道的.而且,面试的时候,我们也会问对方会不会Socket编程?一般来说,很多人都会说,Socket编程基本就是listen,accept以及send,w ...

  8. HTML初体验

    ios讨论群1群:135718460 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,它规定了自己的语法规则,用来表示比"文本"更丰富 ...

  9. HDU 1040 As Easy As A+B [补]

    今天去老校区找她,不想带电脑了,所以没时间A题了 /*******************************************************************/ As Ea ...

  10. jquery 深入学习笔记之中的一个 (事件绑定)

    [jquery 事件绑定] 1.加入元素事件绑定 (1) 加入事件为当前元素 $('p').on('click',function(){ //code here ... }); (2) 加入事件为未来 ...