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. 掌握GCD以及后台永久运行的代码 (使用GCD处理后台线程和UI线程的交互)

    一个例子: 在iPhone上做一个下载网页的功能,就是:在iPhone上放一个按钮,单击按钮时,显示一个转动的圆圈,表示正在进行下载,下载完成后,将内容加载到界面上的一个文本控件上. 使用GCD前: ...

  2. 使用网易云音乐,丢掉QQ音乐吧

    我是一个听音乐的重度用户,基本上每天大约有三分之一的时间里我在使用网易云音乐去听音乐.包括工作写代码的时候,跑步的时候,去上班的途中我都去听.首先需要声明的是,在这里我不是故意的去抹黑其他的音乐产品, ...

  3. Android--保持加速度传感器在屏幕关闭后运行

    由于写论文需要,需要用手机加速度采集数据,关于android加速度传感器的介绍网上一抓一大把,但大多都是大同小异,跟官网文档差不多.自己写了个取加速度传感器的APK,发现数据有点不对劲,原理屏幕一关后 ...

  4. 如何区分 OpenStack Neutron Extension 和 Plugin

    Neutron 里面的 extension 和 plugin 是非常相似的两个概念,我花了好久才貌似搞懂了两者的区别,还不一定完全正确. 在OpenStack 的官网wiki中,可以找到它们两个的定义 ...

  5. windows网络编程的一些理论

    参考自<VC++深入详解> 这是我在看书时记录下来的东西. 注:下面的Socket其实都应该是socket 第14章网络编程 Socket是连接应用程序与网络驱动程序的桥梁,Socket在 ...

  6. 温故知新---重读C#InDepth(一)

    一本好书,或是一本比较有深度的书,就是每次研读的时候都会有新的发现. 好吧,我承认每次读的时候都有泛泛而过的嫌疑~~ 这几年一直专注于C#客户端的开发,逐步从迷迷糊糊,到一知半解,再到自以为是,最后沉 ...

  7. java和linux的编码

    最近要使用中科院计算所的关键词工具NLPIR,用java调用,在windows下测试后放到linux下跑,就发现会有乱码. windows下默认是GBK,linux下是utf-8,因此在意料之中(尽管 ...

  8. Journey Of Code组组员贡献率

    628是该组的组长,前期的主要任务是数据库的设计,中后期加入实现功能模块的工作,实现了文件的上传和解析excel表格的功能,负责协调组员之间的工作和沟通,并且也是最后上台进行演示的人员:所以贡献率有3 ...

  9. win8 配 jdk

    Win8配置jdk 1.7环境变量  环境:win8(32位)64位差不多       jdk1.7    1.右击计算机-属性-高级系统设置-高级-环境变量,弹出“环境变量”对话框,主要是改下面的环 ...

  10. 输入年月,输出月份有几天(分别用了if——else和switch)

    首先是switch做的 class Program { static void Main(string[] args) {/* 题目要求:请用户输入年份,输入月份,输出该月的天数. 思路:一年中月份的 ...