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

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536277.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536277.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536277.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Poor God Water【矩陣快速冪】

Poor God Water 時間限制: 1 Sec 內存限制: 128 MB 提交: 102 解決: 50 [提交] [狀態] [命題人:admin] 題目描述 God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonou…

Transport Ship【多重背包】

Transport Ship 時間限制: 1 Sec 內存限制: 128 MB 提交: 175 解決: 65 [提交] [狀態] [命題人:admin] 題目描述 There are N different kinds of transport ships on the port. The i^th kind of ship can carry the weight of V[i] and the number of the ith kind of ship i…

洛谷P2015 二叉蘋果樹【樹形dp】

P2015 二叉蘋果樹 時間限制 1.00s 內存限制 125.00MB 題目描述 有一棵蘋果樹,如果樹枝有分叉,一定是分2叉(就是說沒有只有1個兒子的結點) 這棵樹共有N個結點(葉子點或者樹枝分叉點),編號為1-N,…

洛谷P2014【樹形dp】

P2014 選課 時間限制 1.00s 內存限制 125.00MB 題目描述 在大學里每個學生,為了達到一定的學分,必須從很多課程里選擇一些課程來學習,在課程里有些課程必須在某些課程之前學習,如高等數學總是在其它課程之前學習。現在有N門功課&…

洛谷P2016 戰略游戲【樹形dp】

P2016 戰略游戲 時間限制 1.00s 內存限制 125.00MB 題目描述 Bob喜歡玩電腦游戲,特別是戰略游戲。但是他經常無法找到快速玩過游戲的辦法。現在他有個問題。 他要建立一個古城堡,城堡中的路形成一棵樹。他要在這棵樹的結點上放置最少數目的士兵&#x…

Shell Pyramid【數學+二分】

Shell Pyramid 時間限制: 1 Sec 內存限制: 128 MB 提交: 291 解決: 95 [提交] [狀態] [命題人:admin] 題目描述 In the 17th century, with thunderous noise, dense smoke and blazing fire, battles on the sea were just the same as those in the modern times. But at tha…

Degree Sequence of Graph G【模擬】

Degree Sequence of Graph G 時間限制: 1 Sec 內存限制: 128 MB 提交: 362 解決: 92 [提交] [狀態] [命題人:admin] 題目描述 Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep lov…

Simple Addition expression【打表+二分】

Simple Addition expression 時間限制: 1 Sec 內存限制: 128 MB 提交: 355 解決: 80 [提交] [狀態] [命題人:admin] 題目描述 A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laug…

洛谷P2622 關燈問題II【狀壓dp+bfs】

P2622 關燈問題II 題目描述 現有n盞燈,以及m個按鈕。每個按鈕可以同時控制這n盞燈——按下了第i個按鈕,對于所有的燈都有一個效果。按下i按鈕對于第j盞燈,是下面3中效果之一:如果a[i][j]為1,那么當這盞燈開了的時候&am…

洛谷P1879 [USACO06NOV]玉米田Corn Fields【狀壓dp】

P1879 [USACO06NOV]玉米田Corn Fields 時間限制 1.00s 內存限制 125.00MB 題目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number…

LEAGUE TABLES【模擬】

LEAGUE TABLES 時間限制: 1 Sec 內存限制: 128 MB 提交: 349 解決: 150 [提交] [狀態] [命題人:admin] 題目描述 League football (known in some circles as soccer) has been played in England since 1888 and is the most popular winter game through most of Europe, jus…

MUSICAL CHAIRS【模擬】

MUSICAL CHAIRS 時間限制: 1 Sec 內存限制: 128 MB 提交: 386 解決: 76 [提交] [狀態] [命題人:admin] 題目描述 Musical chairs is a game frequently played at children’s parties. Players are seated in a circle facing outwards. When the music starts, the players h…

Bomb HDU - 3555【數位dp】

Bomb HDU - 3555 The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence “49”, the power…

不要62 HDU - 2089【數位dp】

不要62 HDU - 2089 杭州人稱那些傻乎乎粘嗒嗒的人為62(音:laoer)。 杭州交通管理局經常會擴充一些的士車牌照,新近出來一個好消息,以后上牌照,不再含有不吉利的數字了,這樣一來,就可…

PACKING【二維01背包】

PACKING 時間限制: 1 Sec 內存限制: 128 MB 提交: 278 解決: 24 [提交] [狀態] [命題人:admin] 題目描述 It was bound to happen. Modernisation has reached the North Pole. Faced with escalating costs for feeding Santa Claus and the reindeer, and serious difficulti…

機器人軍團【動態規劃】

機器人軍團 時間限制: 1 Sec 內存限制: 64 MB 提交: 279 解決: 139 [提交] [狀態] [命題人:admin] 題目描述 邪狼:“怎么感覺這些機器人比我還聰明?不是說人工智能永遠不能超越人類嗎?” 天頂星人:“你們真是目光短淺&#xff0c…

【動態規劃】抄近路

【動態規劃】抄近路 時間限制: 1 Sec 內存限制: 64 MB 提交: 105 解決: 68 [提交] [狀態] [命題人:admin] 題目描述 “最近不知道怎么回事,感覺我們這個城市變成了一個神奇的地方,有時在路上走著走著人就消失了!走著走著突然又有人出現了&…

【動態規劃】魔法石礦

【動態規劃】魔法石礦 時間限制: 1 Sec 內存限制: 64 MB 提交: 116 解決: 27 [提交] [狀態] [命題人:admin] 題目描述 為了找到回家的路,張琪曼施展魔法,從高維空間召喚出了一種叫作“讀者”的生物,據說“讀者”這種生物無所不能,…

Knapsack Cryptosystem【折半+查找】

鏈接:https://ac.nowcoder.com/acm/contest/889/D 來源:牛客網 Amy asks Mr. B problem D. Please help Mr. B to solve the following problem. Amy wants to crack Merkle–Hellman knapsack cryptosystem. Please help it. Given an array {ai} wi…

All men are brothers【并查集+數學】

鏈接:https://ac.nowcoder.com/acm/contest/889/E 來源:牛客網 題目描述 Amy asks Mr. B problem E. Please help Mr. B to solve the following problem. There are n people, who don’t know each other at the beginning. There are m turns. In e…