ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Data Structures > задача:


50712 - Moon algebra

Гость
• Вопросы к жюри (1)

Задачи сборника

• 50677 - The Cottage
• 50414 - Traffic
• 50698 - Ayran Delivery
• 50700 - Candidates for the Mayor
• 50415 - The Scientist
• 50830 - Sorting BST Nodes
• 50803 - Sum of the depths in BST
• 50805 - Sum of the weights in a BST
• 50712 - Moon algebra
• 50978 - Albanian Coders
• 50699 - Fighting Vampires
• 50679 - Jetpack Hurdle Jumping
• 50717 - Hurdle Jumping
• 50692 - How much money?
• 50431 - Sultan's Game
• 50429 - Secret Message
• 50818 - Depth Limited BST

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
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