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. [CareerCup] 14.2 Try-catch-finally Java中的异常处理

    14.2 In Java, does the finally block get executed if we insert a return statement inside the try blo ...

  2. Jenkins进阶系列之——02email-ext邮件通知模板

    发现一个很好的邮件通知模板,根据我的需求定制了一些.分享一下. Default Subject: 构建通知:${BUILD_STATUS} - ${PROJECT_NAME} - Build # ${ ...

  3. html5新增选择器

    分享点html5的学习笔记,比较基础,突然发现通过写博客来记笔记有很多优点呢,平常记得笔记比较简单,复习起来比较吃力,看自己的博客理解起来还比较轻松,而且只有真正理解了才能表达清楚让别人看懂,还锻炼语 ...

  4. 『设计』Laura.Compute 设计思路

    前言: 前一篇文章 <『开源』也顺手写一个 科学计算器:重磅开源> ,继 Laura.Compute 算法开源之后,有 博客园 园友 希望公开一下 Laura.Compute算法 的 设计 ...

  5. 在运行程序时报错:"如果在 Code First 模式下使用,则使用 T4 模板为 Database First 和 Model First 开发生成的代码可能无法 正常运行。若要继续使用 Database First 或 Model First,请确保在执行应用程序的 config 文件中指 定 Entity Framework 连接字符串。若要将这些从 Database First 或 Mod

    解决方案: 将context类下的方法“OnModelCreating”修改为: protected override void OnModelCreating(DbModelBuilder mode ...

  6. [工具类]将时间转换为unix时间戳格式

    写在前面 由于在数据库中存的时间有时间戳格式的数据,在解析以及保存的时候,就需要考虑到数据格式的兼容性问题.看到数据库中的时间字段基本上都是以时间戳格式存储的,没办法,只能将时间进行转换了,考虑到其他 ...

  7. 百度地图 api 功能封装类 (ZMap.js) 新增管理事件功能 [源码下载]

    ZMap 功能说明 ZMap.js 本类方法功能大多使用 prototype 原型 实现: 包含的功能有:轨迹回放,圈画区域可编辑,判断几个坐标是否在一个圆圈内,生活服务查询,从经纬度获取地址信息,地 ...

  8. 调研eclipse安卓平台的开发环境

    首先,我想抒发一下自己的感想.真的没想到这第一次的作业会这样的一波三折,本来以为自己已经弄好了eclipse,也弄过Java,安卓的环境配置应该不在话下,所以一拖再拖,从17号,也就是昨天开始,才着手 ...

  9. java定时器的使用(Timer)

    1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等. 对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Tim ...

  10. XMLHttpRequest的POST中文表单问题解决方案

    XMLHttpRequest的POST中文表单问题解决方案 由于XMLHttpRequest POST的内容是用UTF-8编码,所以在服务端要先把request的编码改为UTF-8. 而且客户端pos ...