SDNU 1499.Problem_H 巴什博奕 Java大数
来源:互联网 发布:胡葆森发家史 知乎 编辑:程序博客网 时间:2024/05/29 18:18
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");}}}}
1 0
- SDNU 1499.Problem_H 巴什博奕 Java大数
- SDNU 1490.Problem_H Miller_Rabin算法判断素数
- SDNU OJ 1060.找第K大数
- python 大数 && Java 大数
- java大数
- java大数
- Java大数
- Java 大数
- java大数
- java 大数
- java大数
- java大数
- java大数
- JAVA 大数
- java 大数
- java 大数
- java 大数
- java 大数
- Eclipse 常见使用技巧
- 标签选择器,类选择器,id选择器
- Lua 的require
- 数位dp
- Java爬虫例子
- SDNU 1499.Problem_H 巴什博奕 Java大数
- 你问我答-关于网页布局上的两个问题
- 普通两个时分计算时间差.C
- Cef功能开发经验总结
- 贪心算法(硬币问题)
- centos7安装php7 php-fpm nginx mariadb及解决php7与php-fpm冲突的问题
- 算法需注意细节
- source命令
- 在Windows平台上编译ElasticFusion