HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50712 - Moon algebra

Guest
• Review clarifications (1)

Volume problems

• 50795 - Trunk
• 50414 - Traffic
• 50698 - Ayran Delivery
• 50978 - Albanian Coders
• 50699 - Fighting Vampires
• 50830 - Sorting BST Nodes
• 50803 - Sum of the depths in BST
• 50805 - Sum of the weights in a BST
• 50712 - Moon algebra
• 50675 - Kruja Boys
• 50415 - The Scientist
• 50679 - Jetpack Hurdle Jumping
• 50717 - Hurdle Jumping
• 50421 - Repairing road segments
• 50431 - Sultan's Game
• 50429 - Secret Message
• 50818 - Depth Limited BST

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ilir Capuni.

Moon algebra

We are given the set {a, b, c} on which we define the following binary operations:

  a * a = b     a * b = b     a * c = a  
  b * a = c     b * b = b     b * c = a  
  c * a = a     c * b = c     c * c = c  

Question: We are given an expression containing N terms from the above set and * between each. Check if it is possible to place () such that the result of the expression evaluates to a.

Input specification
An integer denoting N on the first line and the expression on the second where 1 ≤ N ≤ 10.

Output specification
Print "Yes" or "No", if there is a way.
(No, resp., there is no way) to place the () such that the expression evaluates to a.

 Sample Input I  
 4
 a * c * c * b
 Sample Input II  
 3
 a * b * b
 Sample Input III  
 4
 c * b * a * c
 Sample Output I  
 Yes
 Sample Output II  
 No
 Sample Output III  
 Yes
 Explanation I   
 (a*c)*(c*b)=a*c=a
 Explanation II   
 (a * b) * b = b, a*(b*b) = b
 Explanation III   
 (c*b)*(a*c)


Для отправки решений необходимо выполнить вход.

www.contester.ru