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 ...
随机推荐
- Ubuntu创建新用户的正确姿势
作者按:因为教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步<Ubuntu 创建新用户的正确姿势>原文地址.更欢迎来我的小站看更多原创内容:godbmw.com,进行&q ...
- Java8 默认方法
概述 Java8新增了接口的默认方法.使用default关键字. 默认方法就是接口可以有实现方法,而且不需要实现类来实现其方法.相对于JDK1.8之前的接口来说,新增了可以接口中实现方法. 可以说在接 ...
- 持续集成 自动化构建、测试、部署您的Coding代码
持续集成(Continuous Integration)指的是,频繁地(一天多次)将代码集成到主干. 持续集成的目的,就是让产品可以快速迭代,同时还能保持高质量. 它的核心措施是,代码集成到主干之前, ...
- spring-framework-中文文档一:IoC容器、介绍Spring IoC容器和bean
5. IoC容器 5.1介绍Spring IoC容器和bean 5.2容器概述 本章介绍Spring Framework实现控制反转(IoC)[1]原理.IoC也被称为依赖注入(DI).它是一个过程, ...
- js-dot.js
//小结// toExponential 保留小数点( 0-20 bit ) document.writeln(Math.PI.toExponential(0)); //3e+0 document.w ...
- 如何用ABP框架快速完成项目(2) - 快的定义!
为什么要从快的角度来讲这系列课程呢? 因为快是一个很统一很清晰的标准. 所有人对时间都有一个统一清晰的概念. 比如说这系列课程会讲到的一个实例: 集成LinqToExcel, 用我的方法大概耗时 ...
- Salesforce 应用生命周期管理
应用程序生命周期管理 一个Salesforce系统可以有多个版本,最常见的有: production版本:终端用户实际使用的版本 sandbox版本:沙盒环境,用于开发.测试等 在对Salesforc ...
- 算法:用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
算法:用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型.<剑指offer> 利用栈来进行操作,代码注释写的比较清楚:首先判断两个栈是否是空的:其次当栈二 ...
- svn状态与常见错误
TortoiseSVN 1.6.16是最后一个目录独立管理自身cache的svn版本(每个目录下都有一个隐藏的.svn文件夹) 之后的版本会则会根目录上统一进行管理(只有根目录下有一个隐藏的.svn文 ...
- weblogic报错----Received exception while creating connection for pool "TDMSKD": The Network Adapter could not establish the connection
<2017-8-16 上午08时58分37秒 CST> <Info> <WebLogicServer> <BEA-000377> <Startin ...