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.)
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.
Tell us who will have a beautiful night.(“huahua” or “chaochao”)
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");
}
}
}
}