http://acm.hdu.edu.cn/showproblem.php?pid=1261
import java.util.Scanner;
import java.math.BigInteger;
class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int n,s;
int[] num=new int[30];
BigInteger a,b;
while(cin.hasNext()){ //实现多组输入
n=cin.nextInt();
if(n==0) break;
s=0;
for(int i=0;i<n;i++){
num[i]=cin.nextInt();
s+=num[i];
}
//System.out.println(s);
a=BigInteger.valueOf(1);
for(int i=2;i<=s;i++)
a=a.multiply(BigInteger.valueOf(i));
for(int i=0;i<n;i++){
b=BigInteger.valueOf(1);
for(int j=2;j<=num[i];j++)
b=b.multiply(BigInteger.valueOf(j));
a=a.divide(b);
}
System.out.println(a);
}
}
}
//java 大数判断an和sn-1是否是完全平方数
import java.util.Scanner;
import java.math.BigInteger;
class Main
{
public static boolean iss(BigInteger n)
{
BigInteger l=BigInteger.ZERO;
BigInteger r=n;
while(l.compareTo(r)<=0)
{
BigInteger mid=l.add(r).shiftRight(1); //二分法
BigInteger s=mid.multiply(mid);
int ans;
ans=s.compareTo(n);
if(ans==0)
return true;
else if(ans>0)
r=mid.subtract(BigInteger.ONE);
else
l=mid.add(BigInteger.ONE);
}
return false;
}
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int t=cin.nextInt();
while(t--!=0)
{
BigInteger a=cin.nextBigInteger();
BigInteger b=a.multiply(a.subtract(BigInteger.ONE)).shiftRight(1);
Boolean n=iss(a);
Boolean m=iss(b);
if(n&&m)
System.out.println("Arena of Valor");
else if(n&&!m)
System.out.println("Hearth Stone");
else if(!n&&m)
System.out.println("Clash Royale");
else
System.out.println("League of Legends");
}
}
}
问题 J: Participate in E-sports
时间限制: 2 Sec 内存限制: 128 MB
提交: 177 解决: 48
[提交] [状态] [命题人: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
大数的基本运算 【转载至https://www.cnblogs.com/qie-wei/p/10160143.html】
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger a,b;
while(in.hasNext())
{
a = in.nextBigInteger();
b = in.nextBigInteger();
//四则运算
System.out.println(a.add(b));
System.out.println(a.subtract(b));
System.out.println(a.multiply(b));
System.out.println(a.divide(b));
System.out.println(a.remainder(b));
//大数比较
if(a.compareTo(b)==0)
System.out.println("a==b");
else if(a.compareTo(b)>0)
System.out.println("a>b");
else {
System.out.println("a<b");
}
//绝对值
System.out.println(a.abs());
//幂
int fun = 10;
System.out.println(a.pow(fun));
//大数x进制的字符串表示
int x = 8;
System.out.println(a.toString(x));
//大数返回十进制的字符串表示
System.out.println(a.toString());
}
}
}
toPlainString() //转为普遍计数法输出
//给一个字符串1.238761976E-10
//如何得到0.0000000001238761976这个字符串呢?
BigDecimal bd = new BigDecimal("1.238761976E-10");
System.out.println(bd.toPlainString());
stripTrailingZeros() //去掉末尾0
//给一个字符串1245600.000
//如何得到1245600这个字符串?
BigDecimal bd=new BigDecimal("1245600.000");
System.out.println(bd.stripTrailingZeros());
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
BigDecimal ans = BigDecimal.valueOf(1);
BigDecimal a = in.nextBigDecimal();
Integer n = in.nextInt();
while(n-->0)
ans = ans.multiply(a);
String str = ans.stripTrailingZeros().toPlainString().toString();
if(str.charAt(0)=='0')
str = str.substring(1);
System.out.println(str);
}
in.close();
}
}
import java.math.BigDecimal;
import java.util.Scanner;
public class test1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
BigDecimal a = in.nextBigDecimal();
BigDecimal b = in.nextBigDecimal();
a=a.add(b);
String str = a.stripTrailingZeros().toPlainString().toString();
if(str.charAt(0)=='0')
str = str.substring(1);
System.out.println(str);
}
in.close();
}
}