UVALive 6124 Hexagon Perplexagon 题解
http://vjudge.net/problem/viewProblem.action?id=37480
East Central Regional Contest Problem C: Hexagon Perplexagon
A well known puzzle consists of hexagonal pieces, each with the numbers through printed on the
sides. Each piece has a different arrangement of the numbers on its sides, and the object is to place the
pieces in the arrangement shown below such that the numbers on each shared edge of the arrangement
are identical. Figure (a) is an example of one solution:
(a) Example Solution (b) Position Notation for Output
Rotating any solution also gives another trivially identical solution. To avoid this redundancy, we will
only deal with solutions which have a on the uppermost edge of the central piece, as in the example.
Input
The first line of the input file will contain a single integer indicating the number of test cases. Each case
will consist of a single line containing integers. The first represent the values on piece listed in
clockwise order; the second represent the values on piece , and so on.
Output
For each test case, output the case number (using the format shown below) followed by either the phrase
No solution
or by a solution specification. A solution specification lists the piece numbers in the order
shown in the Position Notation of Figure (b). Thus if piece is in the center, a is printed first; if
piece is at the top, is printed second, and so on. Each test case is guaranteed to have at most one
solution.
Sample Input Sample Output
Case :
Case : No solution
题目
题目是给你7个图中的六边形,每个六边形每个边有一个数字,也就是给你六七四十二个数字。然后这些六边形可以转,你要把7个六边形拼到一起,还符合每条边的数字相同的规则。
题解:
就是深搜啊!先放中间的六边形,然后根据中间的这些数字就能确定其他六边形的方向,然后放上去再看看相邻的两个有没有冲突,有冲突就回溯继续找,没冲突就继续找解。哐哐哐就是深搜,当然好像7重循环来撸也行。我深搜写得飞起来,要把这些转来转去的简直难。
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
//#include<conio.h>
using namespace std;
typedef long long ll; struct six
{
int a[];
int pos[];
}; int t,n;
six a[];
int no[];
int up[];
bool used[];
int getup(int x)
{
if(x==) return a[no[x]].pos[];
int edge=a[no[]].a[(up[]+x-)%];
int pose=a[no[x]].pos[edge];
int pedge=(x+)%;
return (pose-pedge+)%;
} bool gank(int x)
{
if(x<) return false;
//cout<<no[x]<<'.'<<(up[x]+x+3)%6<<"="<<a[ no[x] ].a[ (up[x]+x+3)%6 ]<<" ";
//cout<<no[x-1]<<'.'<<(up[x-1]+x)%6<<'='<<a[ no[x-1] ].a[ (up[x-1]+x)%6 ]<<endl;
if(a[ no[x] ].a[ (up[x]+x+)% ] != a[ no[x-] ].a[ (up[x-]+x)% ]) return true;
//cout<<"false!";
if(x== && a[ no[x] ].a[ (up[x]+)% ] != a[ no[] ].a[ (up[]+)% ]) return true;
return false;
} bool dfs(int x)
{
// printf("x=%d ",x);
// for(int i=0;i<x;i++)
// printf("%d,",no[i]);
// printf("\n");
// printf("up ",x);
// for(int i=0;i<x;i++)
// printf("%d,",up[i]);
// printf("\n");
//getch();
if(x==)
{
return true;
}
for(int i=;i<;i++)
if(!used[i])
{
no[x]=i;
up[x]=getup(x);
if(gank(x)) continue;
used[i]=true;
if(dfs(x+)) return true;
used[i]=false;
}
return false;
} int main()
{
int i,j,x;
scanf("%d",&n);
for(t=;t<=n;t++)
{
for(i=;i<;i++)
for(j=;j<;j++)
{
scanf("%d",&x);
a[i].a[j]=x;
a[i].pos[x]=j;
}
memset(used,false,sizeof(used));
printf("Case %d:",t);
if(dfs())
{
for(i=;i<;i++)
printf(" %d",no[i]);
puts("");
}
else printf(" No solution\n");
}
return ;
}
UVALive 6124 Hexagon Perplexagon 题解的更多相关文章
- UVALive 2521	Game Prediction 题解
		
这个我上来把题目理解错了,我以为所有人的牌都是一样的,感觉这个题太麻烦了吧,而且题目样例过不去啊……后来发现理解错了,给出的数据是他一个人的数据,就是让我们求他一定能赢的轮数,所有的牌是固定的(1 - ...
 - UVALive 7512 November 11th 题解
		
思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多 代码: #include<set> #include<map> #includ ...
 - The 2013 South America/Brazil Regional Contest 题解
		
A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...
 - 130825组队赛-Regionals 2012, North America - East Central NA
		
A.Babs' Box Boutique 一道简单的dfs搜索题,需要两两比较,然后搜到底,得到最大值就行了.比赛时队友写的,我只负责debug..赛后自己写的.. #include<iostr ...
 - 2012 East Central Regional Contest 解题报告
		
昨晚各种莫名其妙卡题. 不过细看这套题还挺简单的.全是各种暴力. 除了最后一道题计算几何看起来很麻烦的样子,其他题都是很好写的吧. A. Babs' Box Boutique 题目大意是给出不超过10 ...
 - 组队练习赛(Regionals 2012, North America - East Central NA)
		
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
 - UVALive 6125 I’ve Got Your Back(gammon) 题解
		
http://vjudge.net/problem/viewProblem.action?id=37481 East Central Regional Contest Problem D: I’ve ...
 - UVALive 7501 Business Cycle(二分)题解
		
题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...
 - UVALive 7503 Change(乱搞)题解
		
题意:你现在有面额为A的纸币,现在需要面额为B的钱(可以是一张也可以是好多张拼成一张),有一台自动售货机,里面有任意价格的商品,售货机兑换出的零钱是随机的(比如找你0.03可能给你0.01+0.01+ ...
 
随机推荐
- SVN中trunk、branches、tags用法详解
			
Subversion有一个很标准的目录结构,是这样的.比如项目是proj,svn地址为svn://proj/. 那么标准的svn布局是:svn://proj/|+-trunk+-branches+-t ...
 - 20145314郑凯杰《信息安全系统设计基础》GDB调试32位汇编堆栈分析
			
20145314郑凯杰<信息安全系统设计基础>GDB调试32位汇编堆栈分析 本篇博客将对第五周博客中的GDB调试32位汇编堆栈进行分析 首先放上以前环境配置的图: 图1: 测试代码: #i ...
 - 第十章 使用MapKit
			
本项目是<beginning iOS8 programming with swift>中的项目学习笔记==>全部笔记目录 ------------------------------ ...
 - 【android】实现一个自己的标题栏
			
完整项目下载 背景:项目中使用标题栏,只是简单的include一个标题栏的视图,赋值.控制元素显示.点击事件都要自己搞,不优雅! 要求: 1:对现有代码入侵最小 2:使用足够简单 OK,围绕着这个需求 ...
 - 那些不好的Socket服务器设计
			
基础Socket 自强的程序猿们都喜欢搞Socket,而且觉得最好自己来封装个组件出来,如果再往上,加入某种数据协议,让上层服务器开发照着此协议走,就是一个小小的框架了.于是,从头开始,最开始的服务器 ...
 - sql server 2008 操作数据表
			
SQL Server表 表的类型: ①临时表 临时表可用来处理中间数据或者用临时表 与其它连接共享进行中的工作.临时表只 能放在tempdb中. 私有临时表(#) 全局临时表(##) ②系 ...
 - 【BZOJ1006】【HNOI2008】神奇的国度(弦图染色)
			
1006: [HNOI2008]神奇的国度 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1467 Solved: 603[Submit][Stat ...
 - EntityFramework_MVC4中EF5 新手入门教程之一 ---1.创建实体框架数据模型
			
Contoso University Web 应用程序 你会在这些教程中构建的应用程序是一个简单的大学网站. 用户可以查看和更新学生. 课程和教师信息.这里有几个屏幕,您将创建. 这个网站的用户界面 ...
 - Daily Scrum – 1/4
			
Meeting Minutes 大家讨论了一下作业的内容,以及用户的反馈,商量了一下长期计划(naive)的完成方式. 好像有些时候用户测试的时候会崩溃,不过我们自己用的时候一直没有出现过,分析可能是 ...
 - iOS 开发ALAsset获取图片缩略图
			
[UIImage imageWithCGImage:[asset aspectRatioThumbnail]