刘汝佳《算法竞赛入门经典(第二版)》习题(七)

这篇博客详细介绍了刘汝佳《算法竞赛入门经典(第二版)》第四章的三个习题,包括4-4骰子涂色(UVa253)、4-5 IP网络(UVa1590)和4-6摩尔斯电码(UVa508)。对于每个题目,博客给出了问题描述、解题思路、源代码和运行结果。骰子涂色问题通过比较骰子的对应面判断是否等价;IP网络问题旨在找到包含所有输入IP地址的最小网络;摩尔斯电码问题要求从可能存在错误的编码中找出可能的匹配单词。
摘要由CSDN通过智能技术生成

刘汝佳《算法竞赛入门经典(第二版)》第四章习题(4-4~4-6)

习题4-4 骰子涂色(Cube paintingUVa253

输入两个骰子,判断两者是否等价。每个骰子用6个字母表示。

例如rbgggrrggbgr是等价的。


原题描述:

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  , t

he 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 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对应62对应5),因此只要将骰子的三组对应面进行比较,若相同即可判断出是同一骰子。


源代码
#include <iostream>
#include <string>

int main (void)
{
    using std::cout;
    using std::cin;
大学生参加学科竞赛有着诸多好处,不仅有助于个人综合素质的提升,还能为未来职业发展奠定良好基础。以下是一些分析: 首先,学科竞赛是提高专业知识和技能水平的有效途径。通过参与竞赛,学生不仅能够深入学习相关专业知识,还能够接触到最新的科研成果和技术发展趋势。这有助于拓展学生的学科视野,使其对专业领域有更深刻的理解。在竞赛过程中,学生通常需要解决实际问题,这锻炼了他们独立思考和解决问题的能力。 其次,学科竞赛培养了学生的团队合作精神。许多竞赛项目需要团队协作来完成,这促使学生学会有效地与他人合作、协调分工。在团队合作中,学生们能够学到如何有效沟通、共同制定目标和分工合作,这对于日后进入职场具有重要意义。 此外,学科竞赛是提高学生综合能力的一种途径。竞赛项目通常会涉及到理论知识、实际操作和创新思维等多个方面,要求参赛者具备全面的素质。在竞赛过程中,学生不仅需要展现自己的专业知识,还需要具备创新意识和解决问题的能力。这种全面的综合能力培养对于未来从事各类职业都具有积极作用。 此外,学科竞赛可以为学生提供展示自我、树立信心的机会。通过比赛的舞台,学生有机会展现自己在专业领域的优势,得到他人的认可和赞誉。这对于培养学生的自信心和自我价值感非常重要,有助于他们更加积极主动地投入学习和未来的职业生涯。 最后,学科竞赛对于个人职业发展具有积极的助推作用。在竞赛中脱颖而出的学生通常能够引起企业、研究机构等用人单位的关注。获得竞赛奖项不仅可以作为个人履历的亮点,还可以为进入理想的工作岗位提供有力的支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值