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] 1.5 Compress String 压缩字符串

    1.5 Implement a method to perform basic string compression using the counts of repeated characters. ...

  2. [CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树

    4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to crea ...

  3. LeetCode:Single Number II

    题目地址:here 题目大意:一个整数数组中,只有一个数出现一次,其余数都出现3次,在O(n)时间,O(1)空间内找到这个出现一次的数 对于”只有一个数出现一次,其余数出现2次“的情况,很简单,只要把 ...

  4. WPF Binding INotifyPropertyChanged 多线程 深入理解

    例子 先来看一个例子 Person.cs public class Person : ObservableObject,INotifyPropertyChanged { private string ...

  5. C语言学习的记忆

    优于他人的技能 会玩双截棍: 我的经验就是Practice make perfect,熟能生巧:还有就是坚持不懈. 关于C语言的学习的回忆 1.我通过老师的教导和课外C语言书籍中学习,和我的技能相比, ...

  6. words in view Moqui resource code

    annotation:注释 注解 documentation:文件  证明文件 embed:嵌入 context:环境  上下文 explicity: 明确的 明白的 conversion: 转化

  7. 35.Android之带删除按钮EditText学习

    今天实现Android里自定义带删除功能的EditText,效果如下: 当输入内容时,EditText变为带有一个删除功能按钮的编辑框,如图: 实现代码很简单,直接上代码, 布局文件xml: < ...

  8. POJ-1273 Drainage Ditches 最大流Dinic

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...

  9. codevs4927 线段树练习5

    题目描述 Description 有n个数和5种操作 add a b c:把区间[a,b]内的所有数都增加c set a b c:把区间[a,b]内的所有数都设为c sum a b:查询区间[a,b] ...

  10. BZOJ4195 程序自动分析

    Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表程序中出现的变量,给定n个形如xi=xj或x ...