UVA 253 Cube painting(未通过)
2016-07-17 18:48
676 查看
We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1.
Figure 1.
Since a cube has 6 faces, our machine can paint a face-numbered cube in
different
ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r,
or g. The
character (
)
from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the
vertical axis by 90
, the one changes into the other.
The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation
of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)
The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.
Figure 1.
Since a cube has 6 faces, our machine can paint a face-numbered cube in
different
ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r,
or g. The
character (
)
from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the
vertical axis by 90
, the one changes into the other.
Input
The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representationof another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)
Output
The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.
Sample Input
rbgggrrggbgr rrrbbbrrbbbr rbgrbgrrrrrg
Sample Output
TRUE FALSE FALSE
// // main.cpp // UVa 253 // // Created by 张嘉韬 on 16/7/17. // Copyright © 2016年 张嘉韬. All rights reserved. // #include <iostream> #include <cstring> #include <cstdio> using namespace std; string a,b,c; int flag; void print(string t) { for(int i=1;i<=6;i++) { cout<<t[i]; } cout<<endl; } string fun1(int n,string temp) { for(int i=1;i<=n;i++) { char t; t=temp[4]; temp[4]=temp[1]; temp[1]=temp[3]; temp[3]=temp[6]; temp[6]=t; } return temp; } string fun2(int n,string temp) { for(int i=1;i<=n;i++) { char t; t=temp[2]; temp[2]=temp[1]; temp[1]=temp[5]; temp[5]=temp[6]; temp[6]=t; } return temp; } string fun3(int n,string temp) { for(int i=1;i<=n;i++) { char t; t=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=temp[3]; temp[3]=t; } return temp; } int comp(string t1,string t2) { for(int i=0;i<=6;i++) { if(t1[i]!=t2[i]) return 0; } return 1; } void dfs(int k,string x) { string temp; for(int i=1;i<=3;i++) { if(k==1) temp=fun1(i,x); else if(k==2) temp=fun2(i,x); else temp=fun3(i,x); if(k==3) { if(strcmp(temp.c_str(),c.c_str())==0) { // print(temp); // print(c); flag=1; } return; } else dfs(k+1,temp); } } void getb() { b[0]='a'; for(int i=0;i<=5;i++) { b[i+1]=a[i]; } } void getc() { c[0]='a'; for(int i=6;i<=11;i++) { c[i-5]=a[i]; } } int main(int argc, const char * argv[]) { //freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin); while(cin>>a) { getb(); getc(); // cout<<a<<endl; // print(b); // print(c); flag=0; dfs(1,b); if(flag==0) cout<<"FALSE"<<endl; else cout<<"TRUE"<<endl; } return 0; }
相关文章推荐
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- 自动发送邮件工具-Auto Send Mail Tool (ASM)
- NSLayoutConstraint - 系统自动布局(详解)
- 安卓开发——安装调试时,提示:INSTALL_FAILED_INSUFFICIENT_STORAGE
- Kafka设计解析:Kafka High Availability (下)
- Kafka设计解析:Kafka High Availability
- Hadoop YARN公平调度(FairScheduler)介绍
- 朴素贝叶斯方法(Naive Bayes)
- POJ-1273 Drainage Ditches(最大流)
- BNU Training 2016.07.11
- An error has occurred,See error log for more details
- Problem B. Rain
- 自学——PaintAndPath
- 修复 apt-get update “the following signatures couldn’t be verified because the public key is not avai
- [区间dp] hdu 2476 string painter
- 19. ubuntu 16.04 LTS 安装mailx