CQOI2013 新数独
这道题也是很暴力的搜索啊……
因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法。
这题最恶心的是读入。现学了一招判断点在哪个块内,用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 新数独的更多相关文章
- 3109. [CQOI2013]新数独【DFS】
Description Input 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第偶数行包含上下方向的符号(^和v). Output 输出包含9行,每行 ...
- B3109 [cqoi2013]新数独 搜索dfs
就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...
- bzoj 3109: [cqoi2013]新数独
#include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...
- BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...
- 【搜索】bzoj3109 [cqoi2013]新数独
搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...
- bzoj 3109: [cqoi2013]新数独【dfs】
按3x3的小块dfs,填数的时候直接满足所有条件即可 #include<iostream> #include<cstdio> #include<cstring> u ...
- 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 ...
随机推荐
- 模拟赛QAQ
100 + 30 + 0 T1 叉叉 题目描述 现在有一个字符串,每个字母出现的次数均为偶数.接下来我们把第一次出现的字母a和第二次出现的a连一条线,第三次出现的和四次出现的字母a连一条线,第五次出现 ...
- Codeforces 375 D Tree and Queries
Discription You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...
- dropwizard问题记录1:如何进行mvn package打包,如何在项目目录下运行
dropwizard的helloworld入门教程,跟着教程一步步写很容易,但是最后打包时暴露了自己底子太差的缺陷 mvn package操作 之前工作中完全没有接触过这种打包方式,都是直接打war包 ...
- mybatis注解@selectKey对于db2数据库的使用
在新增时返回当前新增的主键. 数据库:DB2 用的是mybatis的@selectKey 代码: @InsertProvider(type = Test.class,method="inse ...
- decorate all function in all module
需求: 有package db_api,其下有很多 module 如 plane.py ship.py ufo.py.这些module内定义了方法如 plane.fly(), ship.float() ...
- 加密算法和MD5等散列算法的区别(转)
本文转自http://www.cnblogs.com/eternalwt/archive/2013/03/21/2973807.html 感谢作者 1.在软件开发的用户注册功能中常出现MD5加密这个概 ...
- 【effective c++】定制new和delete
条款49: 了解new-handler的行为 operator new 和 operator delete只适合用来分配单一对象.array所用的内存由operator new[]分配出来,并由ope ...
- BUPT复试专题—字符串转换(2013计院)
题目描述 我们将仅由若干个同一小写字母构成的字符串称之为简单串,例如"aaaa"是一个简单串,而"abcd"则不是简单串.现在给你一个仅由小写字母组成的字符串, ...
- js正則表達式:验证邮箱格式、password复杂度、手机号码、QQ号码
$(function () { $("input[name='sub']").on("click", function () { if (!isEmail($( ...
- 用Perl发送邮件小例子
据传,Perl发送邮件有很多方案,但我只会用Mail::Sender这种方式,也就只能简单谈谈这种方式. 在参考众多网页后,程序书写如下: #!/usr/bin/perl -w use Mail::S ...