hdu 2116 Has the sum exceeded
Has the sum exceeded
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5443 Accepted Submission(s): 1241
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在32符号整数的范围内,这意味着整数A在-2^31到(2^31)-1(含)之间,而A是一个64符号整数,这意味着A在-2^63到(2^63)-1(含)之间。现在我们给出k符号范围,两个k符号整数A和B,你应该检查A和B的和是否超出k符号整数的范围。
输入
会有很多情况需要计算。在每一种情况下,都有一个整数K (2<=K<=64)排在第一行。在这条直线之后,还有另一条直线,它有两个k符号整数A和B。
输出
对于每一种情况,您应该估计总和是否超出范围。如果超出,打印“Yes”,否则打印“WaHaHa”。
代码:
#include<stdio.h>
int main()
{
int K;
while(scanf("%d",&K)!=EOF)
{
long long a,b,max=1;
scanf("%lld %lld",&a,&b);
if (K==64)
max=0x7fffffffffffffff;
else
max=(max<<(K-1))-1;
if(((a>0&&b>0)&&(max-a<b))||((a<0&&b<0)&&(-max-1-a>b)))
printf("Yes\n");
else
printf("WaHaHa\n");
}
return 0;
}