日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Participate in E-sports【Java大数+二分】

發(fā)布時(shí)間:2025/3/8 java 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Participate in E-sports【Java大数+二分】 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Participate in E-sports
時(shí)間限制: 2 Sec 內(nèi)存限制: 128 MB
提交: 194 解決: 53
[提交] [狀態(tài)] [命題人: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.

樣例輸入
復(fù)制樣例數(shù)據(jù)
4
1
2
3
4
樣例輸出
Arena of Valor
Clash Royale
League of Legends
Hearth Stone

題目大意:
輸入一個(gè)數(shù)nnn,記錄另一個(gè)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)?
完全平方數(shù)有: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為完全平方數(shù),則記ju1=trueju1=trueju1=true;
n1n1n1為完全平方數(shù),則記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中的大數(shù)來(lái)寫(xiě),而判斷一個(gè)數(shù)是否為完全平方數(shù),可以通過(guò)二分來(lái)判斷。

代碼:

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

總結(jié)

以上是生活随笔為你收集整理的Participate in E-sports【Java大数+二分】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。