CodeForces 959-A Mahmoud and Ehab and the even-odd game(模拟+找规律)

Problem Description

Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:

  • 1 ≤ a ≤ n.
  • If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd.

If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?

 

Input 

The only line contains an integer n (1 ≤ n ≤ 109), the number at the beginning of the game.

 

Output 

Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.

 

Sample Input   

1

 

Sample Output   

Ehab 

 

Sample Input     

2

 

Sample Output     

Mahmoud

 

Note 

In the first sample, Mahmoud can't choose any integer a initially because there is no positive even integer less than or equal to 1 so Ehab wins.

In the second sample, Mahmoud has to choose a = 2 and subtract it from n. It's Ehab's turn and n = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.

 

题意:

Mahmoud 选择一个正整数n, Mahmoud和Ehab轮流选择一个数a(1 ≤ a ≤ n),由Ehab开始,Ehab每次必须选择一个偶数,Mahmoud每次选择一个奇数,每次选择后n=n-a;直到对方无法选择,则胜利。

 

思路:


通过多列几组数据找规律发现,当n为偶数是Mahmoud胜利,当n为奇数时,Ehab胜利。

 

代码:

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
 int main() 
{
	int N, a;
	scanf("%d", &N);
	if (N % 2 == 0)
	{
		printf("Mahmoud\n");
	}
	else
	{
		printf("Ehab\n");
	}
	return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值