【搜索】bzoj3109 [cqoi2013]新数独
2024-09-04 16:45:30
搜索,没什么好说的。要注意读入。
Code:
#include<cstdio>
#include<cstdlib>
using namespace std;
const int num[][]=
{{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,},
{,,,,,,,,,}};
int map[][][][],vish[][],visl[][],visn[][],chess[][],h=,l=;
char s[];
void Read()
{
for(int k=;k<=;k++)
{
for(int j=;j<=;j++)
{
for(int i=;i<=;i++)
{
scanf("%s",s);
map[h][l][h][l-]= ( s[]=='>' ? - : );
scanf("%s",s);
map[h][l+][h][l]= ( s[]=='<' ? : - );
l+=;
}
for(int i=;i<=;i++)
{
scanf("%s",s);
map[h+][i][h][i]= ( s[]=='v' ? - : );
}
h++;l=;
}
for(int i=;i<=;i++)
{
scanf("%s",s);
map[h][l][h][l-]= ( s[]=='>' ? - : );
scanf("%s",s);
map[h][l+][h][l]= ( s[]=='<' ? : - );
l+=;
}
h++;l=;
}
}
void print()
{
for(int i=;i<=;i++)
{
for(int j=;j<;j++)
printf("%d ",chess[i][j]);
printf("%d\n",chess[i][]);
}
}
bool check(const int &X,const int &Y,const int &Val)
{
if(map[X][Y][X][Y-]==)
if(Val<=chess[X][Y-])return false;
if(map[X][Y][X][Y-]==-)
if(Val>=chess[X][Y-])return false;
if(map[X][Y][X-][Y]==)
if(Val<=chess[X-][Y])return false;
if(map[X][Y][X-][Y]==-)
if(Val>=chess[X-][Y])return false;
return true;
}
void dfs(int x,int y)
{
if(x==)
{
print();
exit();
}
for(int i=;i<=;i++)
if(!vish[x][i]&&!visl[y][i]&&!visn[num[x][y]][i])
if(check(x,y,i))
{
chess[x][y]=i;
vish[x][i]=visl[y][i]=visn[num[x][y]][i]=true;
if(y==)
dfs(x+,);
else
dfs(x,y+);
vish[x][i]=visl[y][i]=visn[num[x][y]][i]=false;
}
}
int main()
{
Read();
dfs(,);
return ;
}
最新文章
- CSS3——transform学习
- 在Ubuntu上安装网易云音乐
- PHP获取具有相同name的多个input表单信息
- 通俗易懂的ListView讲解(Adapter、图、实例)
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
- webkit浏览器渲染影响因素分析
- ASP.NET MVC 开源项目学习之ProDinner (三)
- vs中使用过的扩展和好的nuget库
- [转载]jQuery.extend 函数详解
- Javascript/Jquery 中each() 和forEach()的区别
- Django -- static
- 开源分享,使用Servlet实现360商城
- .NetCore外国一些高质量博客分享
- 使用mkbootfs制作ramdisk根文件系统
- 对世界首款“人工智能”ERP系统HUE的初步了解 - AI ERP - WAP - 万革始
- Hadoop2.7.6_02_HDFS常用操作
- 侧滑返回导航栏以及TabBar隐藏和显示带来的坑
- rails gem更换ruby-china源
- HTTP Status 500 PWC6188 jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Objective-C中的hasPrefix