码迷,mamicode.com
首页 > 其他好文 > 详细

2018焦作网络赛J

时间:2018-09-16 15:25:57      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:row   while   public   valueof   next   tin   art   except   flag   

不知道题意,队友用java大数+二分过了?

 

 

 

技术分享图片
import java.util.Arrays;
import java.util.Scanner;

import java.io.*;
import java.math.*;
public class Main {
    static boolean check(BigInteger num,BigInteger n) {
        boolean flag = true;
        BigInteger a = new BigInteger("0");
        BigInteger cnt = new BigInteger("16");
        BigInteger B1 = new BigInteger("1");
        BigInteger B2 = new BigInteger("2");
        BigInteger B3 = new BigInteger("3");
        BigInteger B4 = new BigInteger("4");
        BigInteger B5 = new BigInteger("5");
        BigInteger B6 = new BigInteger("6");
        BigInteger B7 = new BigInteger("7");
        BigInteger B8 = new BigInteger("8");
        BigInteger B9 = new BigInteger("9");

        if(num.compareTo(B2) == 0 || num.compareTo(B3) == 0 || num.compareTo(B7) == 0 || num.compareTo(B8) == 0) {
            return false;
        } else {
            num = n.mod(cnt);
            if(num.compareTo(BigInteger.ZERO) != 0 && num.compareTo(B1) != 0 && num.compareTo(B4) != 0 && num.compareTo(B9) != 0) {
                return false;
            } else {
                a = sqrt(n);
            }
        }
        if(a.multiply(a).compareTo(n) != 0) {
            return false;
        }
        return true;


    }
    //public static void main(String [] args) throws FileNotFoundException {
        //File file = new File("J.in");
        //InputStream in = new BufferedInputStream(new FileInputStream(file));
        //System.setIn(in);
        public static void main(String [] args) {

        BigInteger B1 = new BigInteger("1");
        BigInteger B2 = new BigInteger("2");
        BigInteger B3 = new BigInteger("3");
        BigInteger B4 = new BigInteger("4");
        BigInteger B5 = new BigInteger("5");
        BigInteger B6 = new BigInteger("6");
        BigInteger B7 = new BigInteger("7");
        BigInteger B8 = new BigInteger("8");
        BigInteger B9 = new BigInteger("9");

        Scanner cin = new Scanner(System.in);
        BigInteger n = new BigInteger("0");
        int t;
        t = cin.nextInt();
        while(t > 0) {
            t--;
            boolean flag1 = true, flag2 = true;
            n = cin.nextBigInteger();
            BigInteger m = n.multiply(n.subtract(B1));
            m = m.divide(B2);
            flag1 = check(n.mod(BigInteger.TEN),n);
            flag2 = check(m.mod(BigInteger.TEN),m);
            
            if(flag1 && flag2) {
                System.out.println("Arena of Valor");
            } else if(flag1&& !flag2 ) {
                System.out.println("Hearth Stone");
            } else if(!flag1&& flag2) {
                System.out.println("Clash Royale");
            } else {
                System.out.println("League of Legends");
            }
        }

    }
    static BigInteger sqrt(BigInteger x) {
        BigInteger now = BigInteger.ZERO ;
        BigInteger l = BigInteger.ONE ;
        BigInteger r = x ;
        while(l.equals(r) == false) {
            BigInteger mid = (l.add(r)).divide(BigInteger.valueOf(2)) ;
            if(now.compareTo(BigInteger.ZERO) != 0 && now.compareTo(mid) == 0) {
                break ;
            } else {
                now = mid ;
            }
            if(now.compareTo(BigInteger.ZERO) == 0) {
                now = mid ;
            }
            if(mid.multiply(mid).compareTo(x) == 1) {
                r=mid ;
            } else {
                l=mid ;
            }
        }
        if(l.multiply(l).compareTo(x) == 1) {
            l=l.subtract(BigInteger.ONE) ;
        }
        return l;

    }
}
View Code

 

2018焦作网络赛J

标签:row   while   public   valueof   next   tin   art   except   flag   

原文地址:https://www.cnblogs.com/LMissher/p/9655129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!