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

 

转载于:https://www.cnblogs.com/fht-litost/p/9664998.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值