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. windows系统下nodejs、npm、express的下载和安装教程——2016.11.09

    1. node.js下载 首先进入http://nodejs.org/dist/,这里面的版本呢,几乎每个月都出几个新的,建议大家下载最新版本,看看自己的电脑是多少位的,别下错了. 下载完解压到你想放 ...

  2. 【题解】P3599 Koishi Loves Construction

    [题解]P3599 Koishi Loves Construction \(\mod n\) 考虑如何构造,发现\(n\)一定在第一位,不然不行.\(n\)一定是偶数或者是\(1\),不然 \(n|\ ...

  3. 【JAVA学习】struts2的action中使用session的方法

    尊重版权:http://hi.baidu.com/dillisbest/item/0bdc35c0b477b853ad00efac 在Struts2里,假设须要在Action中使用session.能够 ...

  4. ABAP 给动态变量赋值

    [转自 http://blog.csdn.net/forever_crazy/article/details/6544830] 需求: 有时写程序的时候,需要给某个动态变量 赋值操作,当字段比较多时, ...

  5. IIS反向代理实现Revel域名访问

    Revel实现域名访问 1.在cmd中启动revel项目,我设置的端口为8000 2.下载IIS的Application Request Routing Cache组件下载地址 3.安装ARR 4.打 ...

  6. 吴恩达机器学习笔记(十二) —— Application Example: Photo OCR(完)

    主要内容: 一.Photo OCR 二.Getting lots of data:artificial data synthesis 三.Ceiling analysis 一.Photo OCR Ph ...

  7. 数据库,序列化数据为json字符串

    create PROCEDURE [dbo].[usp_SerializeJSON] @ParameterSQL as varchar(max) AS BEGIN declare @SQL nvarc ...

  8. iOS数据持久化存储之归档NSKeyedArchiver

    归档是一种很常用的文件储存方法,几乎任何类型的对象都能够被归档储存(实际上是一种文件保存的形式),收集了网上的一些资料并结合自己的一些经验,总结如下. 一.使用archiveRootObject进行简 ...

  9. Linux学习之路(二)文件处理命令之下

    分区格式化: 一块分区想要使用的话,要格式化.格式化主要有两个工作,1,把分区分成等大小的数据块,每个数据块一般为4KB.2在分区之前建一个分区表,给第一个文件建一行相关数据,在分区表里保存了它的io ...

  10. PHP ServerPush (推送) 技术的探讨【转】

    随着人们对Web即时应用需求的不断上升,Server Push(推送)技术在聊天.消息提醒尤其是社交网络等方面开始兴起,成为实时应用的数据流核心.这篇日志试图探讨的便是各种适合于PHP的Push的实现 ...