ACM-ICPC 2018 焦作赛区网络预赛 J Participate in E-sports(大数开方)

https://nanti.jisuanke.com/t/31719

题意

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

分析

 二分高精度开根裸题呀。经典题:bzoj1213

用java套个板子求出平方根,再乘回来检验一下就好。

import java.util.*;
import java.math.*;
public class Main{
    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 n,BigInteger m) {//大数m开n次根
        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(n,r).compareTo(m)<=0) {
            l=r;
            r=r.multiply(a);
        }
        while(l.compareTo(r)<=0) {
            mid=l.add(r).divide(a);
            if(check(n,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();
        BigInteger m=new BigInteger("2");
        while(t--!=0){
            BigInteger n1=sca.nextBigInteger();
            BigInteger n2=n1.multiply(n1.subtract(BigInteger.ONE)).divide(m);
            BigInteger res1=Get(m,n1);
            BigInteger res2=Get(m,n2);
            boolean f1=false,f2=false;
            if(res1.multiply(res1).compareTo(n1)==0) f1=true;
            if(res2.multiply(res2).compareTo(n2)==0) f2=true;
            if(f1&&f2){
                System.out.println("Arena of Valor");
            }else if(f1){
                System.out.println("Hearth Stone");
            }else if(f2){
                System.out.println("Clash Royale");
            }else{
                System.out.println("League of Legends");
            }
            
        }
    }
}

 

posted @ 2018-09-17 21:22  litos  阅读(213)  评论(0编辑  收藏  举报