棋盘覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=45
3 1 2 3
1 5 21
代码如下:
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger;//声明BigInteger大数类 public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int t=cin.nextInt(); while(t-->0) { int n; n=cin.nextInt(); BigInteger a=BigInteger.valueOf(4); for(int i=1; i<n; ++i) a=a.multiply(BigInteger.valueOf(4)); System.out.println(a.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(3))); } } }
比较大小
111111111111111111111111111 88888888888888888888 -1111111111111111111111111 22222222 0 0
a>b a<b
代码如下:
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger;//声明BigInteger大数类 public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { BigInteger a=cin.nextBigInteger(); BigInteger b=cin.nextBigInteger(); BigInteger zero=BigInteger.ZERO; if(a.compareTo(zero)==0&&b.compareTo(zero)==0) break; int f=a.compareTo(b); if(f==-1) System.out.println("a<b"); else if(f==0) System.out.println("a==b"); else System.out.println("a>b"); } } }
递推求值
1 1 1
69087442470169316923566147
代码如下:
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger;//声明BigInteger大数类 public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger fac[]=new BigInteger[100]; while(cin.hasNext()) { for(int i=0; i<=2; ++i) fac[i]=cin.nextBigInteger(); for(int i=3; i<=99; ++i) fac[i]=fac[i-1].add(fac[i-2]).add(fac[i-3]); System.out.println(fac[99]); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-07 02:22:00