编程介的小学生 2017-09-17 08:45 采纳率: 20.5%
浏览 883
已采纳

Hamlet's gambling

Description

"There are a thousand Hamlets in a thousand people's eyes."

--W.William Shakespeare

Lotus is a big fan of Shakespeare. Her favorite tragedy written by Shakespeare is Hamlet, one of the most popular works in English language. However, since Lotus is really a merciful and kindhearted girl, she doesn't like the scene of the final match, in which Hamlet fenced against Laertes. Once she had a dream of Hamlet. In that dream, Hamlet fought with Laertes in another way: flipping coins.

It sounds like gambling. In order to flip the coin in an absolutely fair way, Hamlet got a monkey to do this job instead of people. Before the monkey started to flip, Hamlet and Laertes respectively wrote down an arbitrary sequence of results (we call it a "pattern"). For example, Hamlet wrote down "Head, Tail, Head" while Laertes wrote down "Head, Head, Tail, Tail".It was guaranteed that the pattern of Hamlet's did not occur within the pattern of Laertes', nor did the pattern of Laertes' occur within the pattern of Hamlet's. Then the monkey began to flip the coin over and over and generated a sequence of results, like "Head, Head, Tail, Head, Tail ..." At any time, if the monkey obtained Hamlet's pattern, it stopped flipping and Hamlet won. Otherwise, if the monkey obtained Laertes's pattern, it also stopped flipping and Laertes won.

One example of the gambling is like following: Hamlet's pattern was ""HHT" (H=Head, T=Tail) and his rival's pattern was "HTTT". The monkey flipped the coin and obtained "H, T, H, T, T, H, T, T, T". At that time, Laertes' pattern appeared at the end of the sequence, so the monkey stopped and the judge declared that Laertes won the game.

Now your task is to decide that in Lotus' gambling, who has the higher probability to win the game. Pay attention that since the monkey has no bias, the probabilities to get head or tail in one flip are always equal.
Input

The input contains several test cases. The first line of each case contains two positive integers N and M (0 < N, M <= 100000). N is the length of Hamlet's pattern and M is the length of Laertes'.

The second line contains a string of length N, representing the pattern of Hamlet's. The third line contains a string of length M, representing the pattern of Laertes'. All the strings only contain uppercase letters H' andT'. The input ends by a line of two zeros.
Output

For each test case, output a single line to show your answer. If Hamlet has a better chance to win, output the word 'Hamlet'. If Laertes has a better chance, output the word 'Laertes'. If they have the same probability to win the game, output the word 'Equal'.
Sample Input

1 1
H
T
1 2
T
HH
0 0
Sample Output

Equal
Hamlet

  • 写回答

1条回答

  • threenewbee 2017-09-30 20:18
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站