UVA211-The Domino Effect(dfs)
Problem UVA211-The Domino Effect
Accept:536 Submit:2504
Time Limit: 3000 mSec
Problem Description
Input
The input file will contain several of problem sets. Each set consists of seven lines of eight integers from 0 through 6, representing an observed pattern of pips. Each set is corresponds to a legitimate configuration of bones (there will be at least one map possible for each problem set). There is no intervening data separating the problem sets.
Output
Correct output consists of a problem set label (beginning with Set #1) followed by an echo printing of the problem set itself. This is followed by a map label for the set and the map(s) which correspond to the problem set. (Multiple maps can be output in any order.) After all maps for a problem set have been printed, a summary line stating the number of possible maps appears. At least three lines are skipped between the output from different problem sets while at least one line separates the labels, echo printing, and maps within the same problem set.
Note: A sample input file of two problem sets along with the correct output are shown.
Sample Input
0 6 0 1 2 3 1 1
3 2 6 5 0 4 2 0
5 3 6 2 3 2 0 6
4 0 4 1 0 0 4 1
5 2 2 4 4 1 6 5
5 5 3 6 1 2 3 1
4 2 5 2 6 3 5 4
5 0 4 3 1 4 1 1
1 2 3 0 2 2 2 2
1 4 0 1 3 5 6 5
4 0 6 0 3 6 6 5
4 0 1 6 4 0 3 0
6 5 3 6 2 1 5 3
Sample Ouput
0 6 0 1 2 3 1 1
3 2 6 5 0 4 2 0
5 3 6 2 3 2 0 6
4 0 4 1 0 0 4 1
5 2 2 4 4 1 6 5
5 5 3 6 1 2 3 1
6 18 2 2 3 19 8 8
21 18 28 17 3 16 16 7
21 4 28 17 15 15 5 7
24 4 11 11 1 1 5 12
24 14 14 23 23 13 13 12
26 26 22 22 9 9 10 10
5 0 4 3 1 4 1 1
1 2 3 0 2 2 2 2
1 4 0 1 3 5 6 5
4 0 6 0 3 6 6 5
4 0 1 6 4 0 3 0
6 5 3 6 2 1 5 3
6 6 24 10 10 20 12 11
8 15 15 3 3 17 14 14
8 5 5 2 19 17 28 26
23 1 13 2 19 7 28 26
23 1 13 25 25 7 4 4
27 27 22 22 9 9 21 21
6 6 24 10 10 20 12 11
8 15 15 3 3 17 14 14
8 5 5 2 19 17 28 26
23 1 13 2 19 7 28 26
23 1 13 25 25 7 21 4
27 27 22 22 9 9 21 4
#include <bits/stdc++.h> using namespace std; const int maxn = ;
const int n = ,m = ; int table[maxn][maxn];
int gra[maxn][maxn],ans[maxn][maxn];
int _count;
bool vis[maxn][maxn];
bool used[maxn<<];
int dx[] = {,};
int dy[] = {,}; void init(){
memset(table,,sizeof(table));
memset(vis,false,sizeof(vis));
memset(used,false,sizeof(used));
int i = ,j = ,cnt = ;
for(int len = ;len >= ;len--){
for(int p = j;p < ;p++){
table[i][p] = table[p][i] = cnt++;
}
i++,j++;
}
} void dfs(int x,int y,int cnt){
if(cnt == ){
_count++;
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
printf("%4d",ans[i][j]);
}
printf("\n");
}
printf("\n");
return;
} if(y == m) x++,y = ;
if(vis[x][y]) dfs(x,y+,cnt);
else{
for(int i = ;i < ;i++){
int xx = x+dx[i],yy = y+dy[i];
if(xx>=n || yy>=m) continue;
if(vis[xx][yy] || used[table[gra[x][y]][gra[xx][yy]]]) continue; ans[x][y] = ans[xx][yy] = table[gra[x][y]][gra[xx][yy]];
vis[x][y] = vis[xx][yy] = used[table[gra[x][y]][gra[xx][yy]]] = true;
dfs(x,y+,cnt+);
vis[x][y] = vis[xx][yy] = used[table[gra[x][y]][gra[xx][yy]]] = false;
}
}
} int main()
{
#ifdef GEH
freopen("input.txt","r",stdin);
#endif
init();
int iCase = ;
while(~scanf("%d",&gra[][])){
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
if(i== && j==) continue;
scanf("%d",&gra[i][j]);
}
} if(iCase) printf("\n\n\n");
printf("Layout #%d:\n\n",++iCase);
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
printf("%4d",gra[i][j]);
}
printf("\n");
}
printf("\n");
printf("Maps resulting from layout #%d are:\n\n",iCase);
_count = ;
dfs(,,);
printf("There are %d solution(s) for layout #%d.\n",_count,iCase);
}
return ;
}
UVA211-The Domino Effect(dfs)的更多相关文章
- CF 405B Domino Effect(想法题)
题目链接: 传送门 Domino Effect time limit per test:1 second memory limit per test:256 megabytes Descrip ...
- [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)
Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...
- POJ 1135 Domino Effect(Dijkstra)
点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...
- POJ 1135 Domino Effect (spfa + 枚举)- from lanshui_Yang
Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...
- POJ 1135 Domino Effect (Dijkstra 最短路)
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9335 Accepted: 2325 Des ...
- POJ 1135.Domino Effect Dijkastra算法
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10325 Accepted: 2560 De ...
- zoj 1298 Domino Effect (最短路径)
Domino Effect Time Limit: 2 Seconds Memory Limit: 65536 KB Did you know that you can use domino ...
- TOJ 1883 Domino Effect
Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...
- [POJ] 1135 Domino Effect
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12147 Accepted: 3046 Descri ...
随机推荐
- http协议、web服务器、并发服务器(上)
目录 1. HTTP格式 1.1 HTTP GET请求的格式: 1.2 HTTP POST请求的格式: 1.3 HTTP响应的格式: 2. Web静态服务器-显示固定的页面 3. Web静态服务器-显 ...
- JS 操作svg画图
背景: 一共有3个文件:svg文件,html文件,js文件. 有一个svg图,使用embed标签,引入到了html文件中 svg文件: <svg width="640" he ...
- Laravel 系列入门教程(三)【最适合中国人的 Laravel 教程】
在本篇文章中,我们将尝试构建一个带后台的简单博客系统.我们将会使用到 路由.MVC.Eloquent ORM 和 blade 视图系统. 简单博客系统规划 我们在教程一中已经新建了一个继承自 Eloq ...
- CPU 实用工具
系统版本:CentOS 7.4 top 17:49:04 // 当前时间 up 3:55 // 系统运行时间,格式为时:分 2 users // 当前登录用户数 load average // 三个值 ...
- 洛谷P5245 【模板】多项式快速幂(多项式ln 多项式exp)
题意 题目链接 Sol \(B(x) = \exp(K\ln(A(x)))\) 做完了... 复杂度\(O(n\log n)\) // luogu-judger-enable-o2 // luogu- ...
- loj#6030. 「雅礼集训 2017 Day1」矩阵(贪心 构造)
题意 链接 Sol 自己都不知道自己怎么做出来的系列 不难观察出几个性质: 最优策略一定是先把某一行弄黑,然后再用这一行去覆盖不是全黑的列 无解当且仅当无黑色.否则第一个黑色所在的行\(i\)可以先把 ...
- 洛谷P4063 [JXOI2017]数列(dp)
题意 题目链接 Sol 这题想还是不难想的,就是写起来很麻烦,然后去看了一下loj的最短代码表示只能Orz 首先不难发现一条性质:能够选择的区间一定是不断收缩的,而且新的可选区间一定是旧区间的某个位置 ...
- IIS做反向代理重定向到NodeJS服务器
1. 安装ARR 2. 建立虚拟目录并配置URL Rewrite 3. 启动ARR
- 「Android」adb调试源码(针对dumpsys SurfceFlinger、trace.txt获取)
首先对ADB作简单的阐述,接下来对adb shell dumpsys SurfaceFlinger服务的dump信息的查看.以及ANR问题如何获取trace文件并简单分析. -×*********** ...
- 2015年6月6日,杨学明老师《IT技术人才管理角色转型与实践》专题培训在苏宁云商成功举办!
2015.6.6,在中国南京苏宁总部,研发资深顾问.资深讲师为苏宁易购IT事业部全体产品总监.研发总监进行了为期一天的<IT技术人才管理角色转型与实践>的内训服务. 杨学明老师分别从技术人 ...