Little Boxes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1779 Accepted Submission(s): 664
Total Submission(s): 1779 Accepted Submission(s): 664
Problem Description
Little boxes on the hillside.
Little boxes made of ticky-tacky.
Little boxes.
Little boxes.
Little boxes all the same.
There are a green boxes, and b pink boxes.
And c blue boxes and d yellow boxes.
And they are all made out of ticky-tacky.
And they all look just the same.
Little boxes made of ticky-tacky.
Little boxes.
Little boxes.
Little boxes all the same.
There are a green boxes, and b pink boxes.
And c blue boxes and d yellow boxes.
And they are all made out of ticky-tacky.
And they all look just the same.
Input
The input has several test cases. The first line contains the integer t (1 ≤ t ≤ 10) which is the total number of test cases.
For each test case, a line contains four non-negative integers a, b, c and d where a, b, c, d ≤ 2^62, indicating the numbers of green boxes, pink boxes, blue boxes and yellow boxes.
For each test case, a line contains four non-negative integers a, b, c and d where a, b, c, d ≤ 2^62, indicating the numbers of green boxes, pink boxes, blue boxes and yellow boxes.
Output
For each test case, output a line with the total number of boxes.
Sample Input
4 1 2 3 4 0 0 0 0 1 0 0 0 111 222 333 404
Sample Output
10 0 1 1070
这题把我搞死。。。满心欢喜的觉得超简单很快能过,
第一遍long long 直接加 wa,,,,,
第二遍unsighned long long wa
第三遍改用大数,,,wa
第四遍大数修改,,,wa(再改一点就过)
第五遍想了一个超级超级巧妙的方法,贴错了代码。。。错了代码。。。代码。。。(这种方法可以过的)
第六遍,,队友过(论有个好队友的重要性)
可长点心吧,这题耽误时间我的锅。。。
方法一:
思路:unsigned long long ,所以至少可以用两个long long 分别加两个数,话不多说贴代码
#include<bits/stdc++.h>
using namespace std;
const int MAX = 80;
int x[MAX];
int y[MAX];
int ans[MAX];
int main()
{
int t;
unsigned long long a, b, c, d, temp1, temp2;
while(scanf("%d", &t) != EOF)
{
while(t--)
{
memset(ans, 0, sizeof(ans));
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
temp1 = a+b;
temp2 = c+d;
int cnt1 = 79, cnt2 = 79;
while(temp1)
{
x[cnt1--] = temp1%10;
temp1 /= 10;
}
while(temp2)
{
y[cnt2--] = temp2%10;
temp2 /= 10;
}
int temp = 79;
while(temp >= cnt1 && temp >= cnt2)
{
if(x[temp] + y[temp] >= 10 - ans[temp])
{
ans[temp] = (ans[temp] + x[temp] + y[temp])%10;
ans[temp-1]++;
}
else
ans[temp] += (x[temp] + y[temp]);
temp--;
}
while(temp >= cnt1)
{
if(x[temp] + ans[temp] > 9)
{
ans[temp] = (x[temp] + ans[temp])%10;
ans[temp-1]++;
}
else
ans[temp] += x[temp];
temp--;
}
while(temp >= cnt2)
{
if(y[temp] + ans[temp] > 9)
{
ans[temp] = (y[temp] + ans[temp])%10;
ans[temp-1]++;
}
else
ans[temp] += y[temp];
temp--;
}
while(ans[temp] == 0 && temp != 79)
temp++;
for(int i = temp; i <= 79; i++)
{
cout<<ans[i];
}
cout<<endl;
}
}
return 0;
}
方法二:
思路:四个数相加最大是2^64,unsighned long long 最大为2^64-1,所以当四个数全是2^62时
输出2^64,其他情况正常相加后输出
按例贴代码
#include<bits/stdc++.h>
using namespace std;
const int MAX = 80;
int x[MAX];
int y[MAX];
int ans[MAX];
int main()
{
int t;
unsigned long long a, b, c, d, temp1, temp2;
scanf("%d", &t);
while(t--)
{
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
temp1 = a+b;
temp2 = c+d;
if(a == 4611686018427387904 && b == 4611686018427387904 && c == 4611686018427387904 && d == 4611686018427387904)
cout<<"18446744073709551616"<<endl;
else
cout<<temp1 + temp2<<endl;
}
return 0;
}