骰子涂色(Cube painting)

2023-05-16

Cube painting 

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.

 

picture21

 

 

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 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 br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) 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 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138 tex2html_wrap140

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 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.)

 

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
  

【题目】

       输入两个骰子,判断二者是否等价。

【分析】

       思路源于 点击打开链接 和 点击打开链接。

      1、分析可知1-6,2-5,3-4(指面对面的序号对),所以两个骰子若相同的话,必定面对面的花色是一样的,所以只要判断两个骰子所形成的三个对面是否都能够对应起来就可以了。

以下是我用java语言编写的程序代码(当然也可以查看原文的C语言代码):

import java.util.Scanner;
//分析可知1-6,2-5,3-4,所以两个骰子若相同的话,必定面对面的花色是一样的,
//所以只要判断两个骰子的所形成的三个对面是否都能够对应起来就可以了
// http://www.cnblogs.com/zsboy/archive/2012/08/27/2659066.html
public class CubePainting1 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[][] c1 = new int[300][300];
		int[][] c2 = new int[300][300];
		
		while(input.hasNext()) {
			String s = input.next();
			
			for(int i = 0; i < 300; i++)
				for(int j = 0; j < 300; j++) {
					c1[i][j] = 0;
				}
			
			for(int i = 0; i <= 2; i++) {
				c1[s.charAt(i)][s.charAt(5 - i)]++;
				c1[s.charAt(5 - i)][s.charAt(i)]++;
			}
			
			for(int i = 6; i <= 8; i++) {
				c2[s.charAt(i)][s.charAt(17 - i)]++;
				c2[s.charAt(17 - i)][s.charAt(i)]++;
			}
			
			boolean result = true;
			for(int i = 0; i <= 2; i++) {
				if(c1[s.charAt(i)][s.charAt(5 - i)] != c2[s.charAt(i)][s.charAt(5 - i)]) {
					result = false;
					break;
				}
			}
			
			if(result)
				System.out.println("TRUE");
			else
				System.out.println("FALSE");
		}
	}
}

       2、通过类似枚举的方法,对一个骰子进行翻转旋转,当旋转到至少有一中情况与另外一个骰子的状态相同时,即我们可以判定两者是等价的。可以首先固定某两个对面所形成的轴为中心轴,再对骰子进行顺时针旋转,每次旋转出来的结果均与另个不做任何操作的骰子进行对比。

以下是我用java语言编写的程序代码(当然也可以查看原文的C语言代码,写法略有不同思路则大体相同):

import java.util.Arrays;
import java.util.Scanner;
//类似枚举
//通过方法内参数位置配对时的改变来模拟骰子的旋转
// http://blog.csdn.net/frankiller/article/details/7671606
public class CubePainting2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		String s;
		char[] c1;
		char[] c2;
		int sum;
		while(input.hasNext()) {
			s = input.next();
			
			c1 = s.substring(0, 6).toCharArray();
			c2 = s.substring(6, 12).toCharArray();
			sum = 0;
			
			//cube1:以上下为轴
			sum += rotate(c1[0], c1[5], c1[1], c1[2], c1[3], c1[4], c2);
			sum += rotate(c1[5], c1[0], c1[1], c1[3], c1[2], c1[4], c2);
			//cube1:以前后为轴
			sum += rotate(c1[1], c1[4], c1[0], c1[3], c1[2], c1[5], c2);
			sum += rotate(c1[4], c1[1], c1[0], c1[2], c1[3], c1[5], c2);
			//cube1:以左右为轴
			sum += rotate(c1[2], c1[3], c1[0], c1[1], c1[4], c1[5], c2);
			sum += rotate(c1[3], c1[2], c1[0], c1[4], c1[1], c1[5], c2);
			
			if(sum > 0)
				System.out.println("TRUE");
			else
				System.out.println("FALSE");
		}
	}
	
	//以up和down所形成的轴进行顺时针旋转
	public static int rotate(char up, char down, char a, char b, char c, char d, char[] c2) {
		if(up == c2[0] && down == c2[5] && a == c2[1] && b == c2[2] && c == c2[3] && d == c2[4])
			return 1;
		if(up == c2[0] && down == c2[5] && c == c2[1] && a == c2[2] && d == c2[3] && b == c2[4])
			return 1;
		if(up == c2[0] && down == c2[5] && d == c2[1] && c == c2[2] && b == c2[3] && a == c2[4])
			return 1;
		if(up == c2[0] && down == c2[5] && b == c2[1] && d == c2[2] && a == c2[3] && c == c2[4])
			return 1;
		return 0;
	}
}


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

骰子涂色(Cube painting) 的相关文章

  • 骰子涂色(Cube painting)

    Cube painting We have a machine for painting cubes It is supplied with three different colors blue red and green Each fa
  • oracle group by 两项,Oracle中group by 的扩展函数rollup、cube、grouping sets

    Oracle的group by除了基本使用方法以外 xff0c 还有3种扩展使用方法 xff0c 各自是rollup cube grouping sets 分别介绍例如以下 xff1a 1 rollup 对数据库表emp 如果当中两个字段名
  • Oracle的rollup、cube、grouping sets函数

    Oracle的rollup cube grouping sets函数 Oracle的group by除了基本用法以外 xff0c 还有3种扩展用法 xff0c 分别是rollup cube grouping sets 1 rollup 假设
  • STM32 Cube BMP180 获取温度、气压、海拔

    一 介绍 BMP180中内置有E2PROM xff0c 所以要获取数据 xff0c 就要使用I2C读写E2PROM来实现获取数据 xff01 BMP180的整个流程 xff1a 1 首先要初始化 xff0c 读取几个E2PROM地址上的值共
  • 调试cube生成的f107+lan8720代码

    之前用的w5500 无奈芯片越来越贵了 正好手头上有100来颗lan8720a 直接将方案改了吧 以前在深圳工作时公司的网关正好用的这个方案 直接抄吧 硬件设计网口无晶振 由mcu的mco脚输出 50Mhz模式 其他都是通用连接方式 接下来
  • ODPS-SQL多维度交叉的优化方法探究

    一 背景 odps是阿里集团的大数据计算平台 odps sql语法类似于hive 最近做了一个 项目 需求中用到了大量的维度交叉 等到需求实现后却发现新的问题 cube的交叉维度太多了 最初有17个 而且指标的计算逻辑比较复杂 造成数据加工
  • 动态数据透视表中的行和列总计

    在 SQL Server 2008 中 我有一个包含 3 列的表 tblStock 零件代码 NVARCHAR 50 库存数量 INT 位置 NVARCHAR 50 下面是一些示例数据 PartCode StockQty Location
  • 如何绘制立方体的面?

    我已经做了一个可以在 python 上旋转的立方体 但现在我想为这些面着色 以便在旋转时识别每个面 代码如下 from mpl toolkits mplot3d import Axes3D import matplotlib pyplot
  • 八顶点立方体的法向量

    我正在使用 WEBGL 今天遇到了我的立方体顶点法线的问题 我用立方体网格检查了我的代码来自互联网而且效果很好 问题是 来自互联网的立方体有 24 个顶点 每个面 4 个顶点 6 个面 我认为这对于我的立方体来说太多了 摆弄我的立方体 Fi
  • 颤动 3D 立方体效果

    我想问一下如何在 Flutter 中创建这种效果 也许你知道 flutter 没有 3d 引擎 但你不需要它 你可以使用透视变换 我为你做了一个小例子 import dart math import package flutter mate
  • 如果 CubeField.Orientation = xlPageField 如何设置 PivotField.HiddenItemsList 属性的值

    任务是自动化 OLAP 数据透视表数据过滤 我需要排除名为 sPivotFieldName 的数据透视字段中的一些项目 下面的代码工作得很好 With Worksheets sWorksheetName PivotTables sPivot
  • 具有多个数据库的 SSAS 立方体

    我有 3 个具有相同结构但数据不同的数据库 因为它们来自不同的客户端 现在 我有一个现有的 SSAS 项目 其数据源视图 多维数据集和维度只能使用或访问一个数据库 我想要的是能够使用具有相同结构的多个数据库 并使用它们创建一个多维数据集 每
  • 对 CUBEVALUE 中的多个度量求和

    我尝试了多个不同的函数 CUBESET CUBEVALUE 等 但我似乎无法找到一种方法来在同一公式中对多个度量求和 关于如何完成这项工作有什么建议吗 我进行了大量搜索但找不到方法 想法如下 但这不起作用 CUBEVALUE Connect
  • OLAP 处理时出错

    我是 OLAP 新手 并且弄清楚了如何制作立方体并处理它 然而 当我玩得太多时 我最终遇到了这个错误 OLAP存储引擎中的错误 找不到属性键 表 dbo v MYEntities 列 uniqueId 值 2548 OLAP 中的错误 存储
  • 适用于 asp.net core 的 ADOMD nuget 包

    我正在看ADOMD nuget 包 https www nuget org packages Microsoft AnalysisServices AdomdClient retail amd64 好像不支持ASP NET Core框架 如
  • 在没有窗口的windows桌面上绘制OpenGL

    我见过这样的事情 我想知道这是否可能 假设我运行我的应用程序 它会显示其下方的渲染结果 所以基本上 在没有窗口的情况下在屏幕上渲染 可能还是谎言 注意 想要在 Windows 和 C 中执行此操作 可以使用您的应用程序在其他应用程序的窗口上
  • 在 LINUX 上使用 Python 连接到 OLAP 多维数据集

    我知道如何在 Windows 上使用 Python 连接到 MS OLAP 多维数据集 嗯 至少有一种方法 通常我使用 win32py 包并调用 COM 对象进行连接 import win32com client connection wi
  • 如何在Python中绘制数据立方体

    我想知道是否有一种方法可以在 Python 中绘制数据立方体 我的意思是每个点都有三个坐标 x part points 0 y part points 1 z part points 2 对于每个点我都有一个标量场 t x y z 我想绘制
  • 在网格挤出过程中计算 UV 坐标

    我目前正在为平面形状实现网格挤出算法 让我们假设为矩形 当我拉伸这个矩形时 我为 3d 形状创建了四个新边 产生 8 个新三角形 和一个新底部 当我复制所有顶点以使最终的立方体有 24 个顶点时 这种方法效果很好 但我现在想避免这些额外的顶
  • 在 RGL 中将立方体绘制到 3D 散点图中

    我正在尝试向 3D 散点图添加较小的立方体 网格 具有指定边长 我希望立方体位于原点 我该怎么做呢 我已经玩过cube3d 但我似乎无法将立方体正确定位 也无法使其成为网格 因此我可以看到它包含的数据点 这是我所拥有的 library rg

随机推荐

  • 小明养猪的故事

    1064 小明养猪的故事 分数 1 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 递推 题目描述 话说现在猪肉价格这么贵 xff0c 小明也开始了养猪生活 说来也奇怪 xff0c 他养的猪一出
  • 找新朋友

    1079 找新朋友 分数 1 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 简单数学题公约数 题目描述 新年快到了 xff0c 天勤准备搞一个聚会 xff0c 已经知道现有会员N人 xff0c
  • 生物节律

    1084 生物节律 分数 2 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 数学题 题目描述 有些人相信 xff0c 人从出生开始就有三个生物周期 这三个生物周期分别是体力 xff0c 情绪和
  • 鸡兔同笼

    鸡兔同笼 已知鸡和兔的总数量为n xff0c 总腿数为m 输入n和m xff0c 依次输出鸡的数目和兔的数目 如果无解 xff0c 则输出No answer 样例输入 xff1a 14 32 样例输出 xff1a 12 2 样例输入 xff
  • 赌徒

    1097 赌徒 分数 2 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 查找二分查找 题目描述 有n个赌徒打算赌一局 规则是 xff1a 每人下一个赌注 xff0c 赌注为非负整数 xff0c
  • 排列(permutation)

    排列 xff08 permutation xff09 用1 2 3 xff0c xff0c 9组成3个三位数 abc xff0c def 和 ghi xff0c 每个数字恰好使用一次 xff0c 要求 abc def ghi 61 1 2
  • SQL Server Management Studio 使用方法手记

    本方法只记录自己的操作方法 xff0c 仅供参考 一 下载安装 SQL Server Management Studio V15 0 18424 0 xff0c 链接 xff1a https download csdn net downlo
  • 蛇形填数(矩阵)

    蛇形填数 在 n x n 方针里填入 1 2 xff0c xff0c n x n xff0c 要求填成蛇形 例如 xff1a n 61 4时方阵为 xff1a 10 11 12 1 9 16 13 2 8 15 14 3 7 6 5 4 上
  • WERTYU

    Problem 1343 WERTYU Time Limit 1000 mSec Memory Limit 32768 KB Problem Description A common typing error is to place the
  • 分子量(Molar Mass)

    Molar mass Time limit 3 000 seconds An organic compound is any member of a large class of chemical compounds whose molec
  • 数数字(Digit Counting)

    Digit Counting Time limit 3 000 seconds Trung is bored with his mathematics homeworks He takes a piece of chalk and star
  • 周期串(Periodic Strings)

    周期串 Periodic Strings 如果一个字符串可以由某个长度为k的字符串重复多次得到 xff0c 则称该串以k为周期 例如 xff0c abcabcabcabc以3为周期 xff08 注意 xff0c 它也以6和12为周期 xff
  • 谜题(Puzzle)

    Puzzle Time limit 3 000 seconds Puzzle A children 39 s puzzle that was popular 30 years ago consisted of a 5x5 framewhic
  • 纵横字谜的答案(Crossword Answers)

    Crossword Answers Time limit 3 000 seconds Crossword Answers A crossword puzzle consists of a rectangular grid of black
  • DNA序列(DNA Consensus String)

    DNA Consensus String Time limit 3 000 seconds Figure 1 DNA Deoxyribonucleic Acid is the molecule which contains the gene
  • 古老的密码(Ancient Cipher)

    Ancient Cipher Time limit 3 000 seconds Ancient Roman empire had a strong governmentsystem with various departments incl
  • Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    原文转载自 sunny2038 的CSDN博客文章 原文地址 最近在看Java xff0c 在编译写书上一个例子时 xff0c 由于书上的代码只有一部分 xff0c 于是就自己补了一个内部类 结果编译时出现 xff1a No enclosi
  • 瑞星微开发工具下载镜像的配置方法?

    如何根据 parameter txt 建立配置表 xff1f 首先我们来看下 parameter txt 的内容 xff1a CMDLINE mtdparts 61 rk29xxnand 0x00002000 64 0x00004000 u
  • 特别困的学生(Extraordinarily Tired Students)

    Extraordinarily Tired Students Time limit 3 000 seconds When a student is too tired he can 39 t help sleeping in class e
  • 骰子涂色(Cube painting)

    Cube painting We have a machine for painting cubes It is supplied with three different colors blue red and green Each fa