传送门

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

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

这题最恶心的是读入。现学了一招判断点在哪个块内,用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. 顿悟:Linux是拿来用的,不是拿来折腾的

    Linux是拿来用的,而不是折腾其本身.相信这个道理不少聪明人(实用主义者)都明白,然而总是有那么一群人拿Linux去安装各种发行版.研究Linux命令.配置桌面.美化桌面.研究各种wm/DE.永无止 ...

  2. codechef Tree and Queries Solved

    题目链接: https://www.codechef.com/problems/IITK1P10 大概是:修改点值,求子树节点为0有多少个, DFS序后,BIT 询问,修改 ;    {        ...

  3. Mac Ubuntu ----端口被占用

    Mac下使用lsof(list open files)来查看端口占用情况,lsof 是一个列出当前系统打开文件的工具. 使用 lsof 会列举所有占用的端口列表: 1 $ lsof 使用less可以用 ...

  4. Python 基础教程之包和类的用法

    Python 基础教程之包和类的用法 建立一个文件夹filePackage 在filePackage 文件夹内创建 __init__.py 有了 __init__.py ,filePackage才算是 ...

  5. 使用session来存储用户的登录信息

    对存在cookie端数据进行加密处理,具体代码如下: <?php session_start(); //假设用户登录成功获得了以下用户数据 $userinfo = array( 'uid' =& ...

  6. Quick-Cocos2d3.2RC1在Code IDE中实现代码提示

    之前写Lua最痛苦的就是代码提示问题,如今官方给了IDE很好用.以下说Quick使用IDE加入代码提示问题. 第一步:制作api提示压缩包. 须要使用控制台实现方法例如以下: 1.找到framewor ...

  7. adb问题整理

    1.开启了两个adb,关掉一个,重启eclipse既可 java.io.IOException: 您的主机中的软件中止了一个已建立的连接. at sun.nio.ch.SocketDispatcher ...

  8. java验证码图片

    package com.su.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; impor ...

  9. ID--HANDLE--HWND三者之间的互相转换

    利用PreTranslateMessage,响应按钮控件的按下(WM_LBUTTONDOWN)和松开(WM_LBUTTONUP)   VC的button控制只有两个事件,一个是单击事件,一个事双击事件 ...

  10. HashMap存入大量数据是否要预定义存储空间

    按说HashMap的负载极限为0.75,可是,测试程序并看不出这个结果.待探讨 测试程序如下: 根据结果看不出来预定义有什么影响. public class test { public static ...