TOJ 3471.Happy XiaoXiao Guo

本文介绍了一款简单的游戏策略问题,玩家轮流往洞里放石头,每次可放1、2、4或5颗石头,先达到指定数量者获胜。通过分析发现,石头总数能否被3整除决定了小西瓜是否能赢得比赛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://acm.tju.edu.cn/toj/showp3471.html

3471.    Happy XiaoXiao Guo
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 271    Accepted Runs: 189



Xiao guo's brother have a son, his name is Xiaoxiao guo. In the morning, Xiao guo's brother and his wife went out. So Xiao guo must stay with her nephew. She decide to play a game with him. First, there is an empty hole, they take turns to put some stones in the hole. Every time, 1, 2, 4 or 5 stones were placed in the hole. Two players play in turn, until one player makes a number of stones to be N in the hole and wins the game. Xiaoxiao guo always dose first. Suppose that both Xiao guo and Xiaoxiao guo do their best in the game. Give you a number N, you are to write a program to determine Xiaoxiao guo will happy or not.

Input

The input contains several test cases. The first line of each test case contains an integer number N, denoting the number of stones in the hole finally. You may assume the number of stones in the hole will not exceed 10000. The last test case is followed by one zero.

Output

For each test case, if Xiaoxiao guo win the game,output "Happy", otherwise output "Unhappy".

Sample Input

3
4
7
120
0

Sample Output

Unhappy
Happy
Happy
Unhappy


水题,找规律就行,Unhappy都是3的倍数。

#include <stdio.h>
int main(){
    int n;
    while(~scanf("%d",&n) && n)
        (n % 3) ? printf("Happy\n") : printf("Unhappy\n");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值