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

5 4 3 6 5 3 4 6
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

Layout #1:
   5   4   3   6   5   3   4   6
   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
 
Maps resulting from layout #1 are:
 
   6  20  20  27  27  19  25  25
   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
 
There are 1 solution(s) for layout #1.
 
 
 
Layout #2:
   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
 
Maps resulting from layout #2 are:
 
  16  16  24  18  18  20  12  11
   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
 
  16  16  24  18  18  20  12  11
   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
 
There are 2 solution(s) for layout #2.
 
题解:非常暴力的搜索。想了半天剪枝怎么剪,最后发现不用剪......(想想也对,可能的情况确实比较少)
 
 #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)的更多相关文章

  1. CF 405B Domino Effect(想法题)

    题目链接: 传送门 Domino Effect time limit per test:1 second     memory limit per test:256 megabytes Descrip ...

  2. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  3. POJ 1135 Domino Effect(Dijkstra)

    点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...

  4. 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 ...

  5. POJ 1135 Domino Effect (Dijkstra 最短路)

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9335   Accepted: 2325 Des ...

  6. POJ 1135.Domino Effect Dijkastra算法

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10325   Accepted: 2560 De ...

  7. zoj 1298 Domino Effect (最短路径)

    Domino Effect Time Limit: 2 Seconds      Memory Limit: 65536 KB Did you know that you can use domino ...

  8. TOJ 1883 Domino Effect

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  9. [POJ] 1135 Domino Effect

    Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12147 Accepted: 3046 Descri ...

随机推荐

  1. FastDFS搭建

    a.上传安装时需要的文件 ①:FastDFS_v5.05.tar.gz ②:fastdfs-nginx-module_v1.16.tar.gz ③:libfastcommon-1.0.7.tar.gz ...

  2. Elasticsearch系列(1):认识Elasticsearch

    官方定义 Elasticsearch 是一个实时的分布式搜索分析引擎, 它能让你以一个之前从未有过的速度和规模,去探索你的数据. 它被用作全文检索.结构化搜索.分析以及这三个功能的组合. Elasti ...

  3. Android Studio 学习(六)内容提供器

    运行时权限 使用ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.CALL_PHONE)!=Package ...

  4. C# 程序运行进度显示Lable

    public void test() { Thread.Sleep(); string vvv = ""; ; i < ;i++ ) { vvv = vvv +i.ToStr ...

  5. SPOJ1811 LCS - Longest Common Substring(后缀自动机)

    A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...

  6. chrome 开发者工具,查看元素 hover 样式

    在web开发中,浏览器开发者工具是我们常用的调试工具.我们经常会有这样的需求,就是查看元素的时候需要查看它的hover样式.相信有很多小伙伴都遇到过这样的情形,始终选不中hover后的元素状态.其实在 ...

  7. Vue 组件之间传值

    一.父组件向子组件传递数据 在 Vue 中,可以使用 props 向子组件传递数据. 子组件部分: 这是 header.vue 的 HTML 部分,logo 是在 data 中定义的变量. 如果需要从 ...

  8. 14.Odoo产品分析 (二) – 商业板块(7) –制造(1)

    查看Odoo产品分析系列--目录 一旦你收到了库存中所需的原材料,就可以开始生产终端产品了.ERP系统的部分功能是帮助您根据可用资源调度这些订单.其中一项资源是原产品.其他资源可以包括可用劳动力或特定 ...

  9. Statement和PreparedStatement的异同

    1.首先两个都是java向数据库执行sql语句的对象! java代码连接数据库,并且执行sql语句的步骤如下: //1.注册数据库的驱动程序 Class.forName(driverClass); / ...

  10. WebRTC 简介及服务搭建、测试

    WebRTC主要解决如下三个问题 1.获取音频和视频. 可以访问输入设备,如话筒.(网络)摄像机(头),可以从上述设备获取媒体数据流.目前需要硬件设备支持VP8/VP9,如果设备仅仅支持H.264/H ...