解题思路:
仅记录一下自己的思路,并没有通过,以便后期再进行更改。
参考代码:
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 人评分
Tom数 (C++代码)浏览:868 |
C语言训练-大、小写问题 (C语言代码)浏览:2421 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:949 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:827 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:537 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:654 |
时间转换 (C语言代码)浏览:697 |
敲七 (C++代码)浏览:1119 |
C语言训练-8除不尽的数 (C语言代码)浏览:1469 |