传送门

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

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

这题最恶心的是读入。现学了一招判断点在哪个块内,用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. Croc Champ 2013 - Round 2 C. Cube Problem

    问满足a^3 + b^3 + c^3 + n = (a+b+c)^3 的 (a,b,c)的个数 可化简为 n = 3*(a + b) (a + c) (b + c) 于是 n / 3 = (a + b ...

  2. 【Java TCP/IP Socket】TCP Socket(含代码)

    TCP的Java支持 协议相当于相互通信的程序间达成的一种约定,它规定了分组报文的结构.交换方式.包含的意义以及怎样对报文所包含的信息进行解析,TCP/IP协议族有IP协议.TCP协议和UDP协议.现 ...

  3. android 获得屏幕状态

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  4. CNN网络--AlexNet

    ImageNet Classification with Deep Convolutional Neural Networks 从AlexNet剖析-卷积网络CNN的一般结构 AlexNet是Hint ...

  5. NBUT 1457 Sona (莫队算法)

    题目大意: 求一段区间内 出现的数字的次数的三次方的和 思路分析: 这要水过去的题目真是难,各种优化. 不能用map , 要离散化之后 先处理lowerbound. 优化输入. . . 时间卡的非常紧 ...

  6. Android的activity的生命周期

    activity的生命周期有四个重要的状态:活动,暂停,停止,销毁 基本的方法有:onCreate.onStart.onResume.onPause.onStop.onDestory 最经常使用的方法 ...

  7. IOS UIPickView+sqlite 选择中国全部城市案例

    1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...

  8. 按字节寻址and按字编址

    按字节寻址,存储空间的最小编址单位是字节,按字编址,存储空间的最小编址单位是字,最小编址单位的选择,和存储容量.地址总线宽度都有关联 .同样的存储容量, 粒度小了,地址长度就需要更长 .就是根据不同的 ...

  9. 配置resin支持maven项目

    1. 在resin.conf中找到 <!-- includes the app-default fordefault web-app behavior --> <resin:impo ...

  10. HDU 1312 Red and Black 第一题搜索!

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...