传送门

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

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

这题最恶心的是读入。现学了一招判断点在哪个块内,用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. Java游戏服务器搭建

    一.前言 此游戏服务器架构是一个单服的形式,也就是说所有游戏逻辑在一个工程里,没有区分登陆服务器.战斗服务器.世界服务器等.此架构已成功应用在了多款页游服务器 .在此框架中没有实现相关业务逻辑,只有简 ...

  2. 在Oracle Linux上安装dtrace

    http://www.ohsdba.cn/index.php?g=Home&m=Article&a=show&id=171   时间: 2016-10-09 00:40:04 ...

  3. 【转】 C++ 简单的 Tcp 实现[socket] 客户端与客户端通信

    //  服务器端代码 // Server.cpp : Defines the entry point for the console application.// #include "std ...

  4. BUPT复试专题—哈夫曼树(2010)

    https://www.nowcoder.com/practice/162753046d5f47c7aac01a5b2fcda155?tpId=67&tqId=29635&tPage= ...

  5. SolidEdge如何自动标注尺寸

    1 工具-尺寸-关系助手(必须在编辑草图轮廓状态下,如果你的草图不可编辑,则没有这些选项)   2 框选要自动标注尺寸的东西,这些东西立即变为黄色,然后打对勾   3 选择横纵坐标尺寸原点(其实就是为 ...

  6. HDU 3820 Golden Eggs( 最小割 奇特建图)经典

    Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. ORACLE 8i 遇到报错:ORA-01631: max # extents (505) reached in table

    近期在客户的一个8i生产库上使用statspack.发现alert中有报错: Mon Jun 16 13:17:52 2014 Errors in file /oracle/8.1.7/admin/p ...

  8. 关于cocos2d-x 3.0的点击交互处理

    转自:http://blog.csdn.net/fansongy/article/details/12716671 1.概述     游戏也好,程序也好,仅仅有能与用户交互才有意义.手机上的交互大致能 ...

  9. Python 学习资料分享

    有同学需要学习 Python,确实,随着人工智能被炒的火热,再加上大数据时代,作为程序员的我们,怎么可能坐得住,必须尝尝鲜,给自己增加一项技能,增加自己的竞争了. 内容定位 这方面的学习资料比较多,本 ...

  10. 图像处理之基础---ffmpeg 中的图像缩放

    http://blog.csdn.net/bweaglegao/article/details/8540860 http://www.cnblogs.com/acloud/archive/2011/1 ...