首页 > 其他分享 >HDOJ2116 Has the sum exceeded

HDOJ2116 Has the sum exceeded

时间:2023-02-20 11:02:02浏览次数:35  
标签:BigInteger scanner integer aInteger sum arr HDOJ2116 exceeded new


Has the sum exceeded


Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4869    Accepted Submission(s): 1093


Problem Description


As we all know, in the computer science, an integer A is in the range of 32-signed integer, which means the integer A is between -2^31 and (2^31)-1 (inclusive), and A is a 64-signed integer, which means A is between -2^63 and (2^63)-1(inclusive). Now we give the K-signed range, and two K-signed integers A and B, you should check whether the sum of A and B is beyond the range of K-signed integer or not.


 



Input


There will be many cases to calculate. In each case, there comes the integer K (2<=K<=64) first in a single line. Then following the line, there is another single line which has two K-signed integers A and B.


 



Output


For each case, you should estimate whether the sum is beyond the range. If exceeded, print “Yes”, otherwise “WaHaHa”.


 



Sample Input


32 100 100


 



Sample Output


WaHaHa


 


判断A+B的和是否在(-2^(k-1),2^k  -1)范围里


需要打表,并且使用大数来做


import java.math.BigInteger;
import java.util.Scanner;

public class Main{
private static Scanner scanner;
private static long arr[];

public static void main(String[] args) {
scanner = new Scanner(System.in);
function() ;
while (scanner.hasNext()) {
int n = scanner.nextInt();
String aString = scanner.next();
String bString = scanner.next();
BigInteger aInteger = new BigInteger(aString);
BigInteger bInteger = new BigInteger(bString);
aInteger = aInteger.add(bInteger);// 和

BigInteger maxInteger = new BigInteger("" + (arr[n] - 1));// 范围的最大值
BigInteger minInteger = new BigInteger("" + (-arr[n]));// 范围的最小值
if (aInteger.compareTo(maxInteger) > 0 || aInteger.compareTo(minInteger) < 0) {
System.out.println("Yes");
} else {
System.out.println("WaHaHa");
}
}
}

public static void function() {
arr = new long[65];
arr[1] = 1;
for (int i = 2; i <= 64; i++) {
arr[i] = arr[i - 1] * 2;
}
}
}




标签:BigInteger,scanner,integer,aInteger,sum,arr,HDOJ2116,exceeded,new
From: https://blog.51cto.com/u_15741949/6067974

相关文章

  • [AtCoder Regular Contest 156][D. Xor Sum 5]
    题目链接:D-XorSum5题目大意:给定一个长度为\(N(1\leN\le1000)\)的数组\(A(0\leA_i\le1000)\),以及一个正整数\(K(1\leK\le10^{12})\)。现在要在这\(N\)个数......
  • docker push 到私有仓库提示(Client.Timeout exceeded while awaiting headers)
    如果docker在上传镜像的时候出现该问题,那么大概率是私有仓库的docker不通[root@localhostdocker]#dockerpush192.168.223.136:5000/xiaoniao:v1Thepushrefersto......
  • 【算法】数组的前缀和 Prefix Sum
    算法中有前缀和这样一种很好的数据结构,它能极大地降低区间查询的时间复杂度前缀和-PrefixSum 它是这样的,假如有这样一个数组(序列), A=[a1,a2,a3,a4,a5,a6,......
  • 【题解】CF280D k-Maximum Subsequence Sum
    题目分析:(可能是刚做完毒瘤Ynoi的原因,看这个4k的线段树感觉好简单)可以看一下这个查询的操作,最多\(k\)个不重线段的和的最大值,这个东西大概是网络流的经典题吧。具......
  • 【转载】go.sum中特殊hash如何计算
    Golang为了依赖的安全考虑,在go.mod的基础上引入了go.sum,go.sum文件的作用主要是记录项目依赖的hash值,防止被人修改。在分析具体项目的go.sum文件后可以发现go.sum中不仅......
  • idea启动java服务报错OutOfMemoryError: GC overhead limit exceeded解决方法
    在用idea开发java项目时,启动报内存溢出错误,致服务启动失败:Error:java:java.lang.OutOfMemoryError:GCoverheadlimitexceeded报此错说明启动期间内存不够用了,把idea的启......
  • 05-KafkaConsumer
    1.工作流程1.1消费者组概述ConsumerGroup(CG):由多个consumer组成。形成一个消费者组的条件,是所有消费者的groupId相同。消费者与消费组这种模型可以让整体的消费......
  • HDU 1024 Max Sum Plus Plus
    题目大意:给定一个长度为\(n\)数组,求划分成\(m\)段不相交区间的子段和最大值得问题那么需要考虑得就是对于第i个数字,是否选中它在m个区间中,以及如果选中它那么它在第几个......
  • Codeforces Round #547 (Div. 3) F2. Same Sum Blocks (贪心——最多不重叠区间数量
    题目https://codeforces.com/problemset/problem/1141/F2题意忽略;给出一个数组,求和相等的,不重叠子串的最大数量,并输出(题目有点绕)思路先求出数组前缀和,然后找出......
  • B. Sum of Two Numbers
    B.SumofTwoNumbersThesumofdigitsofanon-negativeinteger$a$istheresultofsummingupitsdigitstogetherwhenwritteninthedecimalsystem.Fore......