Participate in E-sports
时间限制: 2 Sec 内存限制: 128 MB
提交: 194 解决: 53
[提交] [状态] [命题人:admin]
题目描述
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 i candies in the 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 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 N, please judge which game they will choose.

输入
The first line contains an integer T(1≤T≤800), which is the number of test cases.
Each test case contains one line with a single integer: N(1≤N≤10^200).

输出
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

题目大意:
输入一个数nnn,记录另一个n1=1+2+3+⋯+(n−1)=n×(n−1)2n1= 1+2+3+\dots+(n-1)=\cfrac{n\times(n-1)}{2}n1=1+2+3+⋯+(n−1)=2n×(n−1)​
完全平方数有:0(02),1(12),4(22),9(32),16(42)…0(0^2),1(1^2),4(2^2),9(3^2),16(4^2)\dots0(02),1(12),4(22),9(32),16(42)…
若nnn为完全平方数,则记ju1=trueju1=trueju1=true;
若n1n1n1为完全平方数,则记ju2=trueju2=trueju2=true;
若ju1==true&&ju2==trueju1==true \&\& ju2==trueju1==true&&ju2==true,输出 “Arena of Valor”
若ju1==true&&ju2==falseju1==true \&\& ju2==falseju1==true&&ju2==false,输出 “Hearth Stoner”
若ju1==false&&ju2==trueju1==false \&\& ju2==trueju1==false&&ju2==true,输出 “Clash Royale”
若ju1==false&&ju2==falseju1==false \&\& ju2==falseju1==false&&ju2==false,输出 “League of Legends”

解题思路:
由于此题nnn很大,所以可以使用Java中的大数来写,而判断一个数是否为完全平方数,可以通过二分来判断。

代码:

import java.math.*;
import java.util.*;public class Main {public static void main(String[] args) {// TODO code application logic hereScanner cin=new Scanner(System.in);int t=0;t=cin.nextInt();boolean ju1,ju2;while(t!=0) {t--;BigInteger a=BigInteger.ZERO;a=cin.nextBigInteger();BigInteger b=BigInteger.ZERO;b=a.subtract(BigInteger.ONE);b=b.multiply(a);BigInteger c=BigInteger.ONE;c=c.add(c);b=b.divide(c);ju1=false;ju2=false;if(a.compareTo(BigInteger.ONE)==0) {ju1=true;ju2=true;}else {BigInteger l=BigInteger.ONE;BigInteger r=a;BigInteger mid=BigInteger.ZERO;while(r.compareTo(l)>=0) {mid=l.add(r);mid=mid.divide(c);//System.out.println(l+" "+r+" "+mid);BigInteger nape=BigInteger.ZERO;nape=mid.multiply(mid);if(nape.compareTo(a)==0) {ju1=true;break;}else if(nape.compareTo(a)==1) {r=mid.subtract(BigInteger.ONE);}else {l=mid.add(BigInteger.ONE);}}l=BigInteger.ONE;r=b;while(r.compareTo(l)>=0) {mid=l.add(r);mid=mid.divide(c);BigInteger nape=BigInteger.ZERO;//System.out.println(l+" "+r+" "+mid);nape=mid.multiply(mid);if(nape.compareTo(b)==0) {ju2=true;break;}else if(nape.compareTo(b)==1) {r=mid.subtract(BigInteger.ONE);}else {l=mid.add(BigInteger.ONE);}}}if(ju1&&ju2) System.out.println("Arena of Valor");if(ju1&&!ju2) System.out.println("Hearth Stone");if(!ju1&&ju2) System.out.println("Clash Royale");if(!ju1&&!ju2) System.out.println("League of Legends");}}
}

Participate in E-sports【Java大数+二分】相关推荐

  1. games+in+java_Participate in E-sports【Java大数+二分】

    Participate in E-sports 时间限制: 2 Sec 内存限制: 128 MB 提交: 194 解决: 53 [提交] [状态] [命题人:admin] 题目描述 Jessie an ...

  2. Java大数一些个人的见解

    Java大数一些个人的见解 1.为什么要用Java大数? 在我们做题的过程中经常会遇到大数,虽然C/C++处理很快,当时写过的都知道大数不太好敲,不仅浪费时间,而且代码能力不强的人很容易出错.在没有模 ...

  3. [蓝桥杯][算法训练VIP]麦森数(Java大数+快速幂)

    题目描述 形如2p-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2p-1不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=3021377,它有9 ...

  4. Java的学习与java大数运算

    之前就学过一点java,但太久没用知识点早就还给书本,之前在实验室搞到一本java的书,今天来重新温习一下 java的语法大部分和c++语言是一样的,入门非常快,所以在这里基础语句的用法就省略了 输出 ...

  5. HDU-5050 java大数

    题意 给出一对长和宽 输出在这个长和宽之下 尽可能大的分出全部相等的小正方形的边长 输入输出都用二进制表示 输入最大是2^1000 分析 两个长度下都可以分出来就是gcd code import ja ...

  6. 【HDU - 1134 】Game of Connections(JAVA大数加法,卡特兰数)

    题干: This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - ...

  7. java大数输出一位小数_java大数练习 大明A+B(大数小数的高精度)

    title: java大数练习 大明A+B(大数小数的高精度) tags: [acm,杭电,大数] 题意 Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他 ...

  8. “科林明伦杯”哈尔滨理工大学第十届程序设计竞赛——H.直线【JAVA大数 | Python】

    题目传送门 题解 每增加一条线,就可以和之前的n-1条线相交. 那么答案即是 ∑i,i∈[1,n]\sum{i},i∈[1, n]∑i,i∈[1,n],直接前 nnn 项和 n∗(n−1)/2n*(n ...

  9. 2018焦作ICPC E - Resistors in Parallel(规律+Java大数)

    2018焦作ICPC E - Resistors in Parallel题目链接 Time limit  2000 ms Memory limit  1048576 kB In this physic ...

最新文章

  1. mysql 表空间监控shell_一种通过zabbix监控mysql表空间的方法
  2. C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示)
  3. ICS汇编学习笔记——8086的指令系统
  4. ubuntu16.04修改xfce下的gedit的背景颜色
  5. U-net,及其和FCN的区别
  6. CAD图纸管理用什么软件?
  7. 矩阵乘法Java实现
  8. 如何在没有安装安卓环境的mac os上装adb环境.
  9. 基于linux的软件测试,基于linux的Web服务器性能测试
  10. POJ 1861 Network(KUS算法)
  11. 关于pandownload源码的一般性研究与挖掘
  12. 电脑操作系统(Androidx86、Windows、Linux)说明
  13. 牛津3000词汇表(The Oxford 3000™)
  14. Spring入门(二):自动化装配bean
  15. 原创记忆小游戏-HTML网页版
  16. 转载 揭穿号称内存占用极低的软件的诡计
  17. 【愚公系列】2022年11月 Redis数据库-Lua脚本的使用
  18. blackberry 7100
  19. Catlike Coding Unity教程系列 中文翻译 Basics篇(二)Building a Graph
  20. ------什么是作用域

热门文章

  1. Python 线程队列 Queue – FIFO - Python零基础入门教程
  2. Python 线程创建和传参 - Python零基础入门教程
  3. Python return逻辑判断表达式 - 零基础入门教程
  4. jenkins 手动执行_Jenkins Git client插件命令执行漏洞(CVE201910392)
  5. 机械系统计算机控制试卷及答案,机械系统设计试题及答案
  6. redhat配置oracle yum源,Redhat5和6 YUM源配置的区别
  7. 用计算机表白我不喜欢你了,隐藏式表白,表白不一定要用“我喜欢你”这几个字...
  8. android jni 调用java对象_Android NDK开发之Jni调用Java对象
  9. 共享可写节包含重定位_今年双11好房也打折!贝壳兰州站“11.11新房节” 5日开启...
  10. .net core高并发_高并发下的Node.js与负载均衡