解题思路:
仅记录一下自己的思路,并没有通过,以便后期再进行更改。
参考代码:
def Lspin(Out,Mid,In): #左旋 Out = Out + [Out[0]] Out = Out[1:] Mid = Mid + [Mid[0]] Mid = Mid[1:] In = In + [In[0]] In = In[1:] return Out,Mid,In def Rspin(Out,Mid,In): #右旋 Out = [Out[-1]] + Out Out = Out[:-1] Mid = [Mid[-1]] + Mid Mid = Mid[:-1] In = [In[-1]] + In In = In[:-1] return Out,Mid,In def dfs(Out,Mid,In,time): global flag if time == 14 or flag == 1: return for j in range(4): if len(set((In[j],Mid[2*j],Out[3*j]))) == 3: # 如果内,中,外三色不同,则将黄色旋转到内圈 color = [In[j],Mid[2*j],Out[3*j]] if color[1] == 'Y': In[j] = color[1] Mid[2*j] = color[2] Out[3*j] = color[0] elif color[2] == 'Y': In[j] = color[2] Mid[2*j] = color[0] Out[3*j] = color[1] if In.count('Y') == 4 and Mid.count('R') == 8 and Out.count('G') == 12: #判断是否已经达到要求 flag = 1 Out,Mid,In = Lspin(Out,Mid,In) #递归左旋 dfs(Out,Mid,In,time+1) Out,Mid,In = Rspin(Out,Mid,In) #调正 Out,Mid,In = Rspin(Out,Mid,In) #递归右旋 dfs(Out,Mid,In,time+1) if __name__ == '__main__': n = int(input().strip()) for k in range(n): Out = list(input().strip()) Mid = list(input().strip()) In = list(input().strip()) flag= 0 dfs(Out,Mid,In,0) if flag: print('YES') else: print('NO')
0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复