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

版权声明:《学习技巧》每次使用单边大脑的时间不要太久,连续使用左边大脑30分钟就如同连续使用左臂30分钟一样,周期性的交换让大脑两侧能够轮流休息,左脑活动包括了循序渐进的工作,解决逻辑问题与分析,而右脑活动包括了隐喻,创造性思考,模式匹配和可视化。 https://blog.csdn.net/intmainhhh/article/details/82723673

题目传送门

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

解题思路:这道题是用到了java的大整数BigInteger的四则运算和二分查找

代码如下:

import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//速度比Scanner快
	static BigInteger MAX=new BigInteger("1");
	static BigInteger TWO=new BigInteger("2");
	static boolean judge(BigInteger a){
		BigInteger L=BigInteger.ZERO,R=a,M;
		while(R.compareTo(L)>=0){
			M=(L.add(R).divide(TWO));
			int ans=M.multiply(M).compareTo(a);
			if(ans==0)return true;
			else if(ans>0)R=M.subtract(BigInteger.ONE);
			else L=M.add(BigInteger.ONE);
		}
		return false;
	}
	public static void main(String []args) throws IOException{
		for(int i=0;i<200;i++)MAX=MAX.multiply(BigInteger.TEN);
		String s;
		int T=0;
		s=br.readLine();
		T=Integer.parseInt(s);
		while(T-->0){
			s=br.readLine();
			BigInteger a=new BigInteger(s);
			boolean k=judge(a),K=judge((a.multiply(a.subtract(BigInteger.ONE))).divide(TWO));
			if(k&&K)System.out.println("Arena of Valor");
	        else if(K)System.out.println("Clash Royale");
	        else if(k)System.out.println("Hearth Stone");
	        else System.out.println("League of Legends");
		}
	}
}

猜你喜欢

转载自blog.csdn.net/intmainhhh/article/details/82723673
今日推荐