SDNU 1499.Problem_H 巴什博奕 Java大数


1499.Problem_H
Time Limit: 1000 MS    Memory Limit: 32768 KB

Description

Spring is coming, too.(Why do I say too?)

SDNU is a school what has a gender imbalance. There are some beautiful girls in the SDNU ACM-ICPC Association but HuaHua(HH) and ChaoChao(CC) love a little fat girls. Fortunately, there is a girl named Virgo. HH and CC love her and even fight for her. And then one day, virgo comes up a solution about this problem.

Virgo stands at the end of a queue. The queue contains N people. Let HH and CC start from the head of the queue, and each one every time only can choose to take away 1-4 people. When someone can take Vrigo, Vrigo will give him a very beautiful night.

(HH take away people at first and everyone will choose the most beneficial strategy for himself.)


Input

The first line is a number N(N<=500), represents N test case.

Then followed N lines,each line have a number(<=2^1000) mesns the number of the queue.


Output

Tell us who will have a beautiful night.(“huahua” or “chaochao”)


Sample Input

3
2
3
6

Sample Output

huahua
huahua
huahua


    一道典型的巴什博奕,简单说就是给出要找的人的位置,HH和CC一次可以选择往前找1~4个人,HH先找,问谁先找到,假设他们都选择最佳的方案。设n为人数,m为一次找的最多人数,则n=m+1时,由于一次最多只能取m个,所以无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜,所以当一方面对的局势是n%(m+1)=0时,其面临的是必败的局势。所以可以判断当(n-1)%(m+1)==0时后手胜利。

    而这道题特殊的地方在于这道题的数据,给出的位置的范围最大是2^1000,所以这道题不能直接long long处理,而要采用大数的方法来进行处理了,代码是队友写的Java代码,这里copy过来学习一下Java大数的写法→_→

    下面是AC代码:

import java.math.*;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception
	{
		Scanner cin=new Scanner(System.in);
		int  n;
		while(cin.hasNext())
		{
			n=cin.nextInt();
			for(int i=0;i<n;i++)
			{
				BigDecimal a=cin.nextBigDecimal();
				BigDecimal b=new BigDecimal(5D);
				BigDecimal c=new BigDecimal(0D);
				BigDecimal num=a.remainder(b);
				if(num.compareTo(c) == 0)
					System.out.println("chaochao");
				else System.out.println("huahua");
			}
		}
	}
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值