博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM-ICPC2018焦作网络赛 Participate in E-sports(大数开方)
阅读量:4603 次
发布时间:2019-06-09

本文共 3506 字,大约阅读时间需要 11 分钟。

Participate in E-sports

  •  11.44%
  •  1000ms
  •  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(1T800) , 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(1N10200) .

Output

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

样例输入复制

41234

样例输出复制

Arena of ValorClash RoyaleLeague of LegendsHearth Stone

题目来源

 

 

听说牛顿迭代法也能过,这里粘个板子:

 

public static BigInteger sqrt(String x) {        int mlen = x.length();    //被开方数的长度        int len;    //开方后的长度        BigInteger beSqrtNum = new BigInteger(x);//被开方数        BigInteger sqrtOfNum;    //存储开方后的数        BigInteger sqrtOfNumMul;    //开方数的平方        String sString;//存储sArray转化后的字符串        if(mlen%2 == 0)    len = mlen/2;        else    len = mlen/2+1;        char[] sArray = new char[len];        Arrays.fill(sArray, '0');//开方数初始化为0        for(int pos=0; pos
大数开方模板

 

import java.util.Scanner;import java.math.BigInteger;class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        int T = cin.nextInt();        for (int cas = 1; cas <= T; ++cas) {            String str = cin.next();            BigInteger n = new BigInteger(str);            BigInteger m = n.multiply(n.subtract(BigInteger.ONE)).shiftRight(1);            //System.out.println(n);            //System.out.println(m);            boolean nIsSquare = isSquare(n);            boolean mIsSquare = isSquare(m);            if (nIsSquare && mIsSquare) {                System.out.println("Arena of Valor");            } else if (nIsSquare && !mIsSquare) {                System.out.println("Hearth Stone");            } else if (!nIsSquare && mIsSquare) {                System.out.println("Clash Royale");            } else {                System.out.println("League of Legends");            }        }    }        public static boolean isSquare(BigInteger n) {        BigInteger low = BigInteger.ZERO;        BigInteger high = n;        while (low.compareTo(high) <= 0) {            BigInteger mid = low.add(high).shiftRight(1);            BigInteger square = mid.multiply(mid);            int result = square.compareTo(n);            if (result == 0) {                return true;            } else if (result > 0) {                high = mid.subtract(BigInteger.ONE);            } else {                low = mid.add(BigInteger.ONE);            }        }        return false;    }}

 

转载于:https://www.cnblogs.com/yzm10/p/9651696.html

你可能感兴趣的文章
Binding.StringFormat不起作用的原理和解决
查看>>
css hack兼容写法
查看>>
CSS两列布局 一边固定 一边自适应
查看>>
Hadoop2.6.0 动态增加节点
查看>>
图论的一些概念、定理
查看>>
WebView用法
查看>>
Lecture 3: Planning by Dynamic Programming
查看>>
用flash代替图片IMG,设置动态效果链接
查看>>
关于JS的随笔(二)
查看>>
select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)
查看>>
webbug3.0菜鸟笔记1
查看>>
数组相关函数
查看>>
Python 和其他编程语言数据类型的比较
查看>>
T2695 桶哥的问题——送桶 题解
查看>>
HTML5 表单
查看>>
Android群英传》读书笔记 (3) 第六章 Android绘图机制与处理技巧 + 第七章 Android动画机制与使用技巧...
查看>>
关于微信公众平台测试号配置失败的问题
查看>>
【NOIP2001】统计单词个数
查看>>
linux常用端口
查看>>
异常处理
查看>>