HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Exhaustive search & Backtracking > problem:


50712 - Moon algebra

Guest
• Review clarifications (1)

Section problems

• 50713 - Castle and the girls
• 50710 - Permutations
• 50709 - k-ary Strings
• 50708 - Binary Strings
• 50996 - Checkers - the shortest path
• Check-Mate
• 50479 - Bit Compressor
• 50486 - Problems and Programmers
• 50712 - Moon algebra
• 50717 - Hurdle Jumping
• 50840 - Tanker trucks
• 50490 - Across the River
• 50828 - Arranging Time Table
• 51067 - Jumping frog
• 51142 - Jump Min Value
• 51082 - Sum is equal to K - 1
• Post Office Delivery

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