3109: [cqoi2013]新数独

Time Limit: 10 Sec  Memory Limit: 128 MB

Submit: 365  Solved: 229

[Submit][Status][

id=3109" style="color:blue; text-decoration:none">Discuss]

Description

Input

输入一共15行,包括一个新数独的实例。

第奇数行包括左右方向的符号(<和>),第偶数行包括上下方向的符号(^和v)。

 

Output

输出包括9行,每行9个1~9的数字,以单个空格隔开。

输入保证解惟一。

Sample Input

< > > < > <


v v ^ ^ v v ^ ^ ^

< < > < > <

^ ^ ^ v ^ ^ ^ v v

< < < < > >

> < > > > >

v ^ ^ ^ ^ v v v ^

> > > > < >

v v ^ v ^ v ^ v ^

> < < > > >

< < < < > <

v ^ v v v v ^ ^ v

< > > < < >

^ v v v ^ v ^ v v

< > < > < >

Sample Output

4 9 1 7 3 6 5 2 8

2 3 7 8 1 5 6 4 9

5 6 8 2 4 9 7 3 1

9 1 3 6 5 4 8 7 2

8 5 4 9 7 2 1 6 3

7 2 6 3 8 1 9 5 4

3 4 9 5 6 8 2 1 7

1 8 5 4 2 7 3 9 6

6 7 2 1 9 3 4 8 5

dfs的剪枝优化,读入有点麻烦,细心就好了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define HK_reporter main
using namespace std;
int a[10][10],fh[10][10],fl[10][10];
bool flag,vsth[10][10],vstl[10][10],vst[10][10];
inline bool judge(char ch)
{
return ch=='<'||ch=='>'||ch=='v'||ch=='^';
}
inline void readh(int x)
{
char ch;
F(i,1,6)
{
ch=getchar();
while (!judge(ch)) ch=getchar();
fh[x][(i-1)/2+i]=(ch=='>')?1:0;
}
}
inline void readl(int x)
{
char ch;
F(i,1,9)
{
ch=getchar();
while (!judge(ch)) ch=getchar();
fl[x][i]=(ch=='v')?1:0;
}
}
inline void pre()
{
memset(fh,-1,sizeof(fh));
memset(fl,-1,sizeof(fl));
F(i,1,3)
{
readh((i-1)*3+1);
readl((i-1)*3+1);
readh((i-1)*3+2);
readl((i-1)*3+2);
readh((i-1)*3+3);
}
}
inline int num(int x,int y)
{
return (x-1)/3*3+(y-1)/3+1;
}
inline void dfs(int x,int y)
{
if (y>9) x++,y=1;
if (x>9)
{
F(i,1,9)
{
F(j,1,8) printf("%d ",a[i][j]);
printf("%d\n",a[i][9]);
}
flag=true;
return;
}
F(i,1,9) if (!vsth[x][i]&&!vstl[y][i]&&!vst[num(x,y)][i])
{
if (fl[x-1][y]==0&&a[x-1][y]>=i) continue;
if (fl[x-1][y]==1&&a[x-1][y]<=i) continue;
if (fh[x][y-1]==0&&a[x][y-1]>=i) continue;
if (fh[x][y-1]==1&&a[x][y-1]<=i) continue;
vsth[x][i]=vstl[y][i]=vst[num(x,y)][i]=true;
a[x][y]=i;
dfs(x,y+1);
if (flag) return;
vsth[x][i]=vstl[y][i]=vst[num(x,y)][i]=false;
}
}
int HK_reporter()
{
pre();
dfs(1,1);
return 0;
}

bzoj3109【CQOI2013】新数独的更多相关文章

  1. BZOJ3109: [cqoi2013]新数独

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109 搜索一遍.读入注意一下.. #include<cstring> #inclu ...

  2. 【搜索】bzoj3109 [cqoi2013]新数独

    搜索,没什么好说的.要注意读入. Code: #include<cstdio> #include<cstdlib> using namespace std; ][]= {{,, ...

  3. 3109. [CQOI2013]新数独【DFS】

    Description Input 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第偶数行包含上下方向的符号(^和v).   Output 输出包含9行,每行 ...

  4. B3109 [cqoi2013]新数独 搜索dfs

    就是基于普通数独上的一点变形,然后就没什么了,普通数独就是进行一边dfs就行了. 题干: 题目描述 输入格式 输入一共15行,包含一个新数独的实例.第奇数行包含左右方向的符号(<和>),第 ...

  5. CQOI2013 新数独

    传送门 这道题也是很暴力的搜索啊…… 因为数独一开始全是空的,只有许许多多的大小限制条件,那也没必要纠结从哪开始搜索了,直接暴力搜索之后判断一下是否合法. 这题最恶心的是读入.现学了一招判断点在哪个块 ...

  6. bzoj 3109: [cqoi2013]新数独

    #include<cstdio> #include<iostream> using namespace std; ][],li[][],xi[][],a[][],bh[][], ...

  7. bzoj 3109: [cqoi2013]新数独【dfs】

    按3x3的小块dfs,填数的时候直接满足所有条件即可 #include<iostream> #include<cstdio> #include<cstring> u ...

  8. BZOJ3105: [cqoi2013]新Nim游戏 博弈论+线性基

    一个原来写的题. 既然最后是nim游戏,且玩家是先手,则希望第二回合结束后是一个异或和不为0的局面,这样才能必胜. 所以思考一下我们要在第一回合留下线性基 然后就是求线性基,因为要取走的最少,所以排一 ...

  9. BZOJ3105: [cqoi2013]新Nim游戏

    题解: 线性基?类似于向量上的基底. 此题题解戳这里:http://blog.csdn.net/wyfcyx_forever/article/details/39477673 代码: #include ...

随机推荐

  1. kvm安装图终端界面及形界面安装系统

    1.图形界面安装: qemu-img create -f qcow2 /kvm/os/vm-01.qcow2 16G mkdir -p /kvm/iso cd /kvm/iso 上传事先下载好的镜像文 ...

  2. python 04 学生信息管理系统

    今天任务不多,做了学生信息管理系统1.0,使用字典存储学生个体信息,列表存储学生字典.注意dict定义要在循环体内,若定义成全局变量或循环体外,则旧数据会被新数据覆盖.dict属于可变类型数据,内容改 ...

  3. LeetCode(42)Trapping Rain Water

    题目 Given n non-negative integers representing an elevation map where the width of each bar is 1, com ...

  4. Mac系统下VirtualBox装Centos7设置静态IP并连网

    用Virtualbox装了三台Centos7,现在需要设置成三台之间可以相互通信,并且三台都可以连外网. 需求如下: 1. 三台内部相互通信 2. 可以上外网 3. 主机可以虚拟机可以相互通信(she ...

  5. 【02】koala编译中文出错(已放弃不用)

    http://koala-app.com/index-zh.html koala 下载地址.     sass.中文编译出错: 打开 Koala文件夹位置->rubygems->gems- ...

  6. [Go]接口的运用

    在Go语言中,不能通过调用new函数或make函数创建初一个接口类型的值,也无法用字面量来表示一个接口类型的值.可以通过关键字type和interface声明接口类型,接口类型的类型字面量与结构体类型 ...

  7. [HDU5919]Sequence II

    [HDU5919]Sequence II 试题描述 Mr. Frog has an integer sequence of length n, which can be denoted as a1,a ...

  8. Leetcode39.Combination Sum组合总和

    给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限制重复被选 ...

  9. [USACO11NOV]牛的障碍Cow Steeplechase(匈牙利算法)

    洛谷传送门 题目描述: 给出N平行于坐标轴的线段,要你选出尽量多的线段使得这些线段两两没有交点(顶点也算),横的与横的,竖的与竖的线段之间保证没有交点,输出最多能选出多少条线段. 因为横的与横的,竖的 ...

  10. 【multimap的应用】D. Array Division

    http://codeforces.com/contest/808/problem/D #include<iostream> #include<cstdio> #include ...