ACM-ICPC 2018 焦作赛区网络预赛 Participate in E-sports 牛顿迭代

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
i candies in the
ithi^{th}
i
th
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
NthN^{th}
N
th
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
N, please judge which game they will choose.
Input
The first line contains an integer
T(1≤T≤800)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≤N≤10200)N(1 \le N \le 10^{200})
N(1≤N≤10
200
) .
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


java 的大整数以及牛顿迭代求平方根即可;

… >>1 不会T,/2会T( orz )。。。

import org.omg.CORBA.PUBLIC_MEMBER;


import java.math.*;
import java.time.chrono.*;
import java.util.Calendar;
import java.util.Scanner;


public class Main {
      public static void main(String[] args) {
      Scanner cin=new Scanner(System.in);
      int t=cin.nextInt();
      for(int i=0;i<t;i++) {
         BigInteger n=cin.nextBigInteger();
         BigInteger xx=cal(n);
         BigInteger y=n.multiply(n.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
         BigInteger zz=cal(y);
         if(xx.multiply(xx).equals(n)==true) {
             if(zz.multiply(zz).equals(y)==true)
                 System.out.println("Arena of Valor");
             else System.out.println("Hearth Stone");
         }
         else {
             if(zz.multiply(zz).equals(y)==true)
                 System.out.println("Clash Royale");
             else System.out.println("League of Legends");
         }
      }
  }
      static BigInteger cal(BigInteger x) {
          BigInteger ans=BigInteger.valueOf(0);
          if(x.equals(BigInteger.valueOf(0))==true)return ans;
          BigInteger r=BigInteger.valueOf(1);
          BigInteger l=BigInteger.valueOf(-1);
          while(true) {
              BigInteger nxt =r.add(x.divide(r)).shiftRight(1);
              if(nxt.equals(l)==true) {
                  if(l.compareTo(r)==-1)return r;
                  else return l;
              }
              l=r;r=nxt;
          }

      }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值