bzoj 3109: [cqoi2013]新数独【dfs】
按3x3的小块dfs,填数的时候直接满足所有条件即可
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=15;
int a[N][N],ans[N][N];
char b[N][N],c[N][N];
bool v[5][5][N],h[N][N],l[N][N];
char read()
{
char p=getchar();
while(p!='^'&&p!='v'&&p!='<'&&p!='>')
p=getchar();//cerr<<p<<endl;
return p;
}
bool ok(int x,int y,int i)
{//cerr<<b[x][y-1]<<" "<<x<<" "<<y<<" "<<i<<" "<<a[x][y-1]<<endl;
if(h[x][i]||l[y][i])
return 0;
if(y%3!=1)
{
if(b[x][y-1]=='>'&&a[x][y-1]<i)
return 0;
if(b[x][y-1]=='<'&&a[x][y-1]>i)
return 0;
}
if(x%3!=1)
{
if(c[x-1][y]=='^'&&a[x-1][y]>i)
return 0;
if(c[x-1][y]=='v'&&a[x-1][y]<i)
return 0;
}
return 1;
}
void dfs(int p,int q,int x,int y)
{
if(ans[1][1])
return;
if(p==3)
{
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
ans[i][j]=a[i][j];
return;
}
for(int i=1;i<=9;i++)
if(!v[p][q][i]&&ok(p*3+x,q*3+y,i))
{
v[p][q][i]=1,h[p*3+x][i]=1,l[q*3+y][i]=1,a[p*3+x][q*3+y]=i;
if(q==2&&x==3&&y==3)
dfs(p+1,0,1,1);
else if(x==3&&y==3)
dfs(p,q+1,1,1);
else if(y==3)
dfs(p,q,x+1,1);
else
dfs(p,q,x,y+1);
v[p][q][i]=0,h[p*3+x][i]=0,l[q*3+y][i]=0,a[p*3+x][q*3+y]=0;
}
}
int main()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<6;j++)
b[i*3+1][j/2*3+j%2+1]=read();
for(int j=1;j<=9;j++)
c[i*3+1][j]=read();
for(int j=0;j<6;j++)
b[i*3+2][j/2*3+j%2+1]=read();
for(int j=1;j<=9;j++)
c[i*3+2][j]=read();
for(int j=0;j<6;j++)
b[i*3+3][j/2*3+j%2+1]=read();
}
// for(int i=1;i<=9;i++)
// {
// for(int j=1;j<=9;j++)
// cerr<<c[i][j];
// cerr<<endl;
// }
dfs(0,0,1,1);
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
printf("%d ",ans[i][j]);
puts("");
}
return 0;
}
bzoj 3109: [cqoi2013]新数独【dfs】的更多相关文章
- bzoj 3109: [cqoi2013]新数独
#include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...
- 3109. [CQOI2013]新数独【DFS】
Description Input 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第偶数行包含上下方向的符号(^和v). Output 输出包含9行,每行 ...
- B3109 [cqoi2013]新数独 搜索dfs
就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...
- bzoj 3105: [cqoi2013]新Nim游戏 异或高消 && 拟阵
3105: [cqoi2013]新Nim游戏 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 535 Solved: 317[Submit][Stat ...
- BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...
- CQOI2013 新数独
传送门 这道题也是很暴力的搜索啊…… 因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法. 这题最恶心的是读入.现学了一招判断点在哪个块 ...
- 【搜索】bzoj3109 [cqoi2013]新数独
搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...
- BZOJ 3105 [CQOI2013]新Nim游戏 ——线性基
[题目分析] 神奇的题目,两人都可以第一次取走足够多堆的石子. nim游戏的规则是,如果异或和为0,那么就先手必输,否则先手有必胜策略. 所以只需要剩下一群异或和为0就可以了. 先排序,线性基扫一遍即 ...
- BZOJ 3105: [cqoi2013]新Nim游戏
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3105 题意是要取一些数使得剩余的数xor和的子集不为0 拟阵.求解极大线性无关组.贪心从大到小 ...
随机推荐
- palindrome-partitioning I&II——回文切割、深度遍历
I: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
- IOS开发——网络编程总汇
关于IOS的网络编程,大家都会想到C实现的底层BSD ,CFNetwork和NSURL之类的库,虽然如今非常多第三方库非常方便,可是作为一名开发人员,也须要了解底层代码. 以下的思维导图是关于眼下开发 ...
- 基于bootstrap_后台管理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CodeForces 318D Ants
题目链接 题意: 有n仅仅蚂蚁和m次询问 n仅仅蚂蚁初始所有位于起点(0,0)处.每4仅仅蚂蚁在同一格就会以该格为中心向上下左右四个方向爬一格 一仅仅向上,一仅仅向下,一仅仅向左.一仅仅向右 假设每一 ...
- Redis HyperLogLog及应用
参考:http://www.runoob.com/redis/redis-hyperloglog.html Redis 在 2.8.9 之后的版本中,添加了 HyperLogLog 结构,用来做基数统 ...
- u-boot简单学习笔记(三)——AR9331 uboot启动分析
1.最开始系统上电后 ENTRY(_start)程序入口点是 _start 由board/ap121/u-boot.lds引导 2._start: cpu/mips/start.S 是第一个源程序文 ...
- stm32GPIO8种模式
stm32GPIO工作模式及用途 1.浮空输入GPIO_IN_FLOATING ——浮空输入,可以做KEY识别,RX1 2.带上拉输入GPIO_IPU——IO内部上拉电阻输入 ...
- LeetCode(67)题解: Add Binary
https://leetcode.com/problems/add-binary/ 题目: Given two binary strings, return their sum (also a bin ...
- Scaling with Microservices and Vertical Decomposition
Scaling with Microservices and Vertical Decomposition – dev.otto.de https://dev.otto.de/2014/07/29/s ...
- 在C语言中使用libiconv进行编码转换的示例
libiconv_sample.c #include <stdio.h> #include <malloc.h> #include "libiconv/iconv.h ...