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(1≤T≤800) , 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(1≤N≤10200) .

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

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

听说牛顿迭代法也能过,这里粘个板子:https://blog.csdn.net/f_zyj/article/details/77852787

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% == ) len = mlen/;
else len = mlen/+;
char[] sArray = new char[len];
Arrays.fill(sArray, '');//开方数初始化为0
for(int pos=; pos<len; pos++){
//从最高开始遍历数组,每一位都转化为开方数平方后刚好不大于被开方数的程度
for(char num=''; num<=''; num++){
sArray[pos] = num;
sString = String.valueOf(sArray);
sqrtOfNum = new BigInteger(sString);
sqrtOfNumMul = sqrtOfNum.multiply(sqrtOfNum);
if(sqrtOfNumMul.compareTo(beSqrtNum) == ){
sArray[pos]-=;
break;
}
}
}
return new BigInteger(String.valueOf(sArray));
}

大数开方模板

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

ACM-ICPC2018焦作网络赛 Participate in E-sports(大数开方)的更多相关文章

  1. 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat

    题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...

  2. 焦作网络赛K-Transport Ship【dp】

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...

  3. 焦作网络赛B-Mathematical Curse【dp】

    A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...

  4. 焦作网络赛E-JiuYuanWantstoEat【树链剖分】【线段树】

    You ye Jiu yuan is the daughter of the Great GOD Emancipator. And when she becomes an adult, she wil ...

  5. 焦作网络赛L-Poor God Water【矩阵快速幂】

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  6. ACM-ICPC2018焦作网络赛 Mathematical Curse(dp)

    Mathematical Curse 22.25% 1000ms 65536K   A prince of the Science Continent was imprisoned in a cast ...

  7. ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)

    Transport Ship 25.78% 1000ms 65536K   There are NN different kinds of transport ships on the port. T ...

  8. HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...

  9. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

随机推荐

  1. Cauchy sequence Hilbert space 希尔波特空间的柯西序列

    http://mathworld.wolfram.com/HilbertSpace.html A Hilbert space is a vector space  with an inner prod ...

  2. BZOJ2328: [HNOI2011]赛车游戏

    BZOJ2328: [HNOI2011]赛车游戏 Description 题解Here! 一开始被题面那一长串的描述吓到了,一直没敢做... 然后尝试着硬着头皮读懂题面. 然后...这不是贪心么??? ...

  3. Chart.js 动态图表的使用

    一.相关资料 1. 简介 Chart.js 是一个基于 HTML5 的简单的面向对象的图表库,支持包括 IE7/8 和所有现代浏览器.支持六种图标:曲线图(Linecharts).柱状图(Barcha ...

  4. Spring Aop切点

    切点用于准确定位应该在什么地方应用切面的通知.通知和切点是切面的最基本的元素.在Spring AOP中要使用AspectJ的切点表达式来定义切点.下面我们列出Spring AOP所支持的AspectJ ...

  5. 窥探 Swift 之别具一格的 Struct 和 Class

    说到结构体和类,还是那句话,只要是接触过编程的小伙伴们对这两者并不陌生.但在Swift中的Struct和Class也有着令人眼前一亮的特性.Struct的功能变得更为强大,Class变的更为灵活.St ...

  6. (C)结构数组

    结构数组 对于大小相同但是类型不同的数组,定义结构体数组对其很有帮组.例如: char *keyword[NKEYS]; int keycount[NKEYS]; 这两个数组大小相同,因此 可以用另一 ...

  7. oops信息的分析【转】

    本文转载自:https://blog.csdn.net/zhangchiytu/article/details/8303172 oops是英语口语"糟糕"的意思,当LINUX 内核 ...

  8. Mac OS访问Windows共享文件夹

    原文地址:http://blog.csdn.net/jinhill/article/details/7246922 最近开始研究Mac OS,遇到的第一个问题就是如何在Mac OS中访问Windows ...

  9. loj#2269. 「SDOI2017」切树游戏

    还是loj的机子快啊... 普通的DP不难想到,设F[i][zt]为带上根玩出zt的方案数,G[i][zt]为子树中的方案数,后面是可以用FWT优化的 主要是复习了下动态DP #include< ...

  10. RQNOJ 569 Milking Time:dp & 线段问题

    题目链接:https://www.rqnoj.cn/problem/569 题意: 在一个数轴上可以摆M个线段,每个线段的起始终止端点给定(为整数),且每个线段有一个分值,问如何从中选取一些线段使得任 ...