(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"); } } } }