常见的有棋盘覆盖和A+B问题,这类问题牵扯到的数值都比较大,如果用一般的数值类型,肯定输出不了,所以就要想一个办法,怎么把大数转换一下输出。

A+B Problem II

时间限制:3000 ms | 内存限制:65535 KB

难度:3

描述

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

A,B must be positive.

输入

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

输出

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation.

样例输入

2

1 2

112233445566778899 998877665544332211

样例输出

Case 1:

1 + 2 = 3

Case 2:

112233445566778899 + 998877665544332211 = 1111111111111111110

偷懒的我,用java很简单

import java.util.*;

import java.math.*;

public class Main {

public static void main(String[] args) {

Scanner sc=new Scanner (System.in);

int l=sc.nextInt();

for(int i=1;i<=l;i++){

if(i!=1) System.out.println();

BigInteger a,b;

a=sc.nextBigInteger();

b=sc.nextBigInteger();

System.out.println("Case "+i+":");

System.out.println(a+" + "+b+" = "+a.add(b));

}

}

}

java.math提供用于执行任意精度整数算法 (BigInteger) 和任意精度小数算法 (BigDecimal) 的类。

棋盘覆盖

时间限制:3000 ms | 内存限制:65535 KB

难度:3

描述

在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的2×2方格(图2为其中缺右下角的一个),去覆盖2k×2k未被覆盖过的方格,求需要类似图2方格总的个数s。如k=1时,s=1;k=2时,s=5

输入

第一行m表示有m组测试数据;

每一组测试数据的第一行有一个整数数k;

输出

输出所需个数s;

样例输入

3

1

2

3

样例输出

1

5

21

import java.util.*;

import java.math.*;

public class Main {

public static void main(String[] args) {

Scanner sc=new Scanner (System.in);

int l=sc.nextInt();

BigInteger m=BigInteger.valueOf(4);

BigInteger n=BigInteger.valueOf(-1);

BigInteger o=BigInteger.valueOf(3);

for(int i=1; i<=l; i++) {

if(i!=1) System.out.println();

BigInteger s;

int k=sc.nextInt();

s=((m.pow(k)).add(n)).divide(o);

System.out.println(s);

}

}

}

强大的java大数问题。

java棋盘问题_0x03大数问题(JAVA解决棋盘覆盖,A+B Problem II)相关推荐

  1. java小学生加减法_大数加减法 - java实现

    计算机处理的各种数据类型都有个范围,超出范围的就处理不了. 如果做超大数运算加减乘除,普通方法肯定是不行的,那么我们遇到大数的运算怎么处理呢?今天介绍一种大数加减乘除运算的方法 思路: 1. 将两个特 ...

  2. Java位运算优化:位域、位图棋盘等

    快速小测试:如何重写下面的语句?要求不使用条件判断语句交换两个常量的值. if (x == a) x= b; else x= a; 答案: x= a ^ b ^ x; //此处变量x等于a或者等于b ...

  3. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法 java.lang.ClassNotFoundException: com.

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法 java.lang.ClassNotFoundException: com.m ...

  4. java无阻塞执行脚本,JAVA调用Shell脚本-及阻塞的解决方法

    JAVA调用Shell脚本--及阻塞的解决办法 用java调用shell,使用 Process p=Runtime.getRuntime().exec(String[] cmd); Runtime.e ...

  5. java.lang.UnsatisfiedLinkError:no jhdf5 in java.library.path问题的解决

    笔者在MyEclipse中进行HDF文件的读写,遇到了java.lang.UnsatisfiedLinkError:no jhdf5 in java.library.path的问题.笔者详细地记录了整 ...

  6. Adobe flash cs5 的Java运行时环境初始化错误 完美解决方法

    Adobe flash cs5 的Java运行时环境初始化错误 完美解决方法 下载网络上的Adobe flash cs5 精简版(绿色版),Java运行时环境初始化时出现错误,你可能需要重装Flash ...

  7. java精确除法计算,四舍五入 Java问题通用解决代码

    java精确除法计算,四舍五入 Java问题通用解决代码 参考文章: (1)java精确除法计算,四舍五入 Java问题通用解决代码 (2)https://www.cnblogs.com/svenne ...

  8. java开发中遇到的问题及解决方法(持续更新)

    java开发中遇到的问题及解决方法(持续更新) 参考文章: (1)java开发中遇到的问题及解决方法(持续更新) (2)https://www.cnblogs.com/LiuYanYGZ/p/6112 ...

  9. Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法

    Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法 参考文章: (1)An ...

最新文章

  1. NDK 提示undefined reference to xxx“的解决办法
  2. 新能源汽车市场发展趋势
  3. linux下oracle自动创建实例脚本
  4. 使用组件构建Android应用程序
  5. 华为2021在美专利数量首次进前五,超越英特尔苹果微软
  6. 【转载】2010年最全最新令人无语语录
  7. IIR数字滤波器的设计及应用——MATLAB
  8. JAVA学习-JAVA实现1-100的累加
  9. 如何重装win8系统,win8系统重装的方法
  10. Batch Normalization 反向传播(backpropagation )公式的推导
  11. java集合和数组互转
  12. C语言中基础数据类型的取值范围——整型溢出问题
  13. 拓端tecdat|R语言改进的股票配对交易策略分析SPY-TLT组合和中国股市投资组合
  14. Java 高级工程师面试题总结-参考答案(已拿Offer)
  15. matlab划分训练集验证和测试集代码_Matlab随机划分训练集和测试集
  16. 网络安全基础——对称加密算法和非对称加密算法(+CA数字证书)
  17. prisma1.0实践
  18. DOS运行GHOST加参数
  19. “顺丰杯”包装设计大赛背后的故事:浅谈顺丰的产学研包装生态圈布局
  20. wi7计算机如何查看隐藏的文件夹,win7隐藏的文件夹怎么显示?隐藏文件夹查看及设置方法...

热门文章

  1. Go的json解析:Marshal与Unmarshal
  2. 图解HTTP--笔记
  3. rsync 更改配置后, 无需手动重启
  4. ubuntu9.10中更改启动顺序(grub2的配置)
  5. 20170824图论选讲部分习题
  6. iOS 分类添加属性
  7. 2021年终总结-向着阳光前进
  8. 如何基于 String 实现同步锁?
  9. 测试 MySQL 性能的几款工具
  10. 数据科学家最需要什么技能?