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 题解的更多相关文章

  1. UVALive 2521 Game Prediction 题解

    这个我上来把题目理解错了,我以为所有人的牌都是一样的,感觉这个题太麻烦了吧,而且题目样例过不去啊……后来发现理解错了,给出的数据是他一个人的数据,就是让我们求他一定能赢的轮数,所有的牌是固定的(1 - ...

  2. UVALive 7512 November 11th 题解

    思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多 代码: #include<set> #include<map> #includ ...

  3. The 2013 South America/Brazil Regional Contest 题解

    A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...

  4. 130825组队赛-Regionals 2012, North America - East Central NA

    A.Babs' Box Boutique 一道简单的dfs搜索题,需要两两比较,然后搜到底,得到最大值就行了.比赛时队友写的,我只负责debug..赛后自己写的.. #include<iostr ...

  5. 2012 East Central Regional Contest 解题报告

    昨晚各种莫名其妙卡题. 不过细看这套题还挺简单的.全是各种暴力. 除了最后一道题计算几何看起来很麻烦的样子,其他题都是很好写的吧. A. Babs' Box Boutique 题目大意是给出不超过10 ...

  6. 组队练习赛(Regionals 2012, North America - East Central NA)

    A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...

  7. UVALive 6125 I’ve Got Your Back(gammon) 题解

    http://vjudge.net/problem/viewProblem.action?id=37481 East Central Regional Contest Problem D: I’ve ...

  8. UVALive 7501 Business Cycle(二分)题解

    题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...

  9. UVALive 7503 Change(乱搞)题解

    题意:你现在有面额为A的纸币,现在需要面额为B的钱(可以是一张也可以是好多张拼成一张),有一台自动售货机,里面有任意价格的商品,售货机兑换出的零钱是随机的(比如找你0.03可能给你0.01+0.01+ ...

随机推荐

  1. Python解析器源码加密系列之(二):一次使用标准c的FILE*访问内存块的尝试

    摘要:由于近期打算修改Python解释器以实现pyc文件的加密/解密,出于保密的要求,解密之后的数据只能放在内存中,不能写入到文件中.但是后续的解析pyc文件的代码又只能接受FILE*作为入参,所以就 ...

  2. 《深入理解计算机系统》深入实践之——vim深入研究

    vim 用户手册中,大部分的例子都是在讲 vim 如何高效编写代码,由此可见,vim 是一款面向于程序员的多功能编辑器,即使某些功能 vim 无法直接完成,借助其丰富的插件资源,必定可以达成目标,这就 ...

  3. 1.1Linux 系统简介(学习过程)

    =====课程笔记===== 一.Linux 为何物 Linux 是一个操作系统,就像你多少已经了解的 Windows(xp,7,8)和 Max OS . Linux 也就是系统调用和内核两层,我们使 ...

  4. 学习笔记——Maven实战(四)基于Maven的持续集成实践

    Martin的<持续集成> 相信很多读者和我一样,最早接触到持续集成的概念是来自Martin的著名文章<持续集成>,该文最早发布于2000年9月,之后在2006年进行了一次修订 ...

  5. xsd、wsdl生成C#类的命令行工具使用方法

    1.xsd生成C#类命令 示例:xsd <xsd文件路径> /c /o:<生成CS文件目录> <其他参数> 参数说明: /c 生成为cs文件,/d 生成DataSe ...

  6. SpringMVC实现Restful风格的WebService

    1.环境 JDK7 MyEclipse2014 tomcat8 maven 3.3.3 spring4.1.4 2.创建maven工程 使用MyEclipse创建maven工程的方式可以参考这篇博文( ...

  7. 12.C#yield return和yield break及实际应用小例(六章6.2-6.4)

    晚上好,各位.今天结合书中所讲和MSDN所查,聊下yield关键字,它是我们简化迭代器的关键. 如果你在语句中使用了yield关键字,则意味着它在其中出现的方法.运算符或get访问器是迭代器,通过使用 ...

  8. 年前辞职-WCF入门学习(3)

    前言 [2了,刚写好的,手贱,点了删除,还真TMD的删除了,只好重写] 今天周六,去同事家聚了一个餐,感觉各种豪华. 废话不多说,前两集大致介绍了一下什么是WCF以及和WCF相关的WebService ...

  9. 第一节Unity3D简介

    Unity是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎.Unity ...

  10. Apache MINA(一)

    Apache MINA is a network application framework which helps users develop high performance and high s ...