ACM-ICPC 2018 焦作赛区网络预赛 J(二分+JAVA高精)

传送门

题面:

  •  65536K

Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know which one to choose, so they use a way to make decisions.

They have several boxes of candies, and there are ii candies in the i^{th}ith box, each candy is wrapped in a piece of candy paper. Jessie opens the candy boxes in turn from the first box. Every time a box is opened, Jessie will take out all the candies inside, finish it, and hand all the candy papers to Justin.

When Jessie takes out the candies in the N^{th}Nth box and hasn't eaten yet, if the amount of candies in Jessie's hand and the amount of candy papers in Justin's hand are both perfect square numbers, they will choose Arena of Valor. If only the amount of candies in Jessie's hand is a perfect square number, they will choose Hearth Stone. If only the amount of candy papers in Justin's hand is a perfect square number, they will choose Clash Royale. Otherwise they will choose League of Legends.

Now tell you the value of NN, please judge which game they will choose.

Input

The first line contains an integer T(1 le T le 800)T(1≤T≤800) , which is the number of test cases.

Each test case contains one line with a single integer: N(1 le N le 10^{200})N(1≤N≤10200) .

Output

For each test case, output one line containing the answer.

样例输入复制

4
1
2
3
4

样例输出复制

Arena of Valor
Clash Royale
League of Legends
Hearth Stone

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

题意:

    让你分别判断n或(n-1)*n/2是否是完全平方数。

题目分析:

    二分高精度开根裸题呀。原题在这里呀:bzoj1213

    比赛的时候演了队友呀,前面的K题用错误的数据疯狂hack队友了呀。自闭之后疯狂肝没学会的后缀自动机呀,然后这个裸题连开都没有开呀(伤心欲绝.jpg)。

    言归正传.jpg:bzoj1213是开任意根的模板呀,这里我们只需要开个平方根(取个n==2)就好了,套个板子重新乘一乘判断一哈就过了呀。

代码:

import java.util.*;
import java.math.*;
public class Main{
	//二分开根板子
    public static BigInteger check(BigInteger n,BigInteger x) {
        BigInteger ans=BigInteger.valueOf(1);
        BigInteger a=BigInteger.valueOf(1);
        for(BigInteger i=BigInteger.ZERO;i.compareTo(n)<0;i=i.add(a)) {
            ans=ans.multiply(x);
        }
        return ans;
    }
    static BigInteger Get(BigInteger m) {
    	BigInteger l=BigInteger.ZERO;
        BigInteger a=BigInteger.valueOf(2);
        BigInteger b=BigInteger.valueOf(1);
        BigInteger r=BigInteger.valueOf(1);
        BigInteger mid=BigInteger.ZERO;
        while(check(BigInteger.valueOf(2),r).compareTo(m)<=0) {
            l=r;
            r=r.multiply(a);
        }
        while(l.compareTo(r)<=0) {
            mid=l.add(r).divide(a);
            if(check(BigInteger.valueOf(2),mid).compareTo(m)<=0) l=mid.add(b);
            else r=mid.subtract(b);
        }
        return r;
    }
    public static void main(String[]args) {
    	int T;
        Scanner sca=new Scanner(System.in);
        T=sca.nextInt();
        while(T--!=0) {
        	BigInteger m=sca.nextBigInteger();
            BigInteger res1=Get(m);
            BigInteger n;
            n=m.multiply(m.subtract(BigInteger.ONE)).divide(BigInteger.valueOf(2));
            BigInteger res2=Get(n);
            BigInteger tmp1=res1.multiply(res1);
            BigInteger tmp2=res2.multiply(res2);
            if(tmp1.equals(m)&&tmp2.equals(n)) {
            	System.out.println("Arena of Valor");
            }
            else if(tmp1.compareTo(m)==0&&tmp2.compareTo(n)!=0) {
            	System.out.println("Hearth Stone");
            }
            else if(tmp1.compareTo(m)!=0&&tmp2.compareTo(n)==0) {
            	System.out.println("Clash Royale");
            }
            else System.out.println("League of Legends");
        }
    }
}
原文地址:https://www.cnblogs.com/Chen-Jr/p/11007193.html