【BZOJ】2056: gift? 高精度?

Description

Input

输入的第一行为一个整数t。 接下来t行,每行包含九个自然数。

Output

输出t行 每行一个整数,表示2^a+2^b+2^c+2^d+2^e+2^f+2^g+2^h+i。

Sample Input

1
21 30 0 0 0 0 0 0 2147483647

Sample Output

3223322629
【数据规模】
40% t<=1000
100% t<=100000 a,b,c,d,e,f,g,h<=60 i<=9223372036854775808

HINT

Source

题解:

  今天一天的大好时光啊……就浪费在了这一个题的身上啊……真是整整一天……居然还感冒了QAQ

   这题完全可以避免高精度……发现只有最差的情况才会出现超出unsignd long long 的情况的说。

  于是特判一下就好啦,其余暴力

  (P.S Python不知道为什么RE了……代码先放上,求神犇帮忙看看为什么Python会RE……)

  c++ code:

 

#include <cstdio>
const int MAXN = 10;
int a[MAXN];
int main()
{
    int i, j, T;
    unsigned long long s,temp;
    scanf("%d", &T);
    while (T--)
    {
        s = 0;
        for (i = 1; i <= 8; i++)
        {
            scanf("%d", &a[i]);
            s += (1LL<<a[i]);
        }
        scanf("%llu", &temp);
        if (s != 1LL << 63 || temp != s)
        printf("%llu\n", s + temp);
        else puts("18446744073709551616");
    }
}

Python code:


T=input()
nums=[0 for x in range(200)]
while(T>0):
    T = T - 1
    S=0
    temp=1
    nums = map(int, raw_input().split(' '))
    for i in range (0,8):
        temp=1
        for j in range (0,nums[i]):
            temp=temp*2
        S=S+temp
    S=S+nums[8]
    print(S)
posted @ 2016-10-12 17:05  BeyondW  阅读(297)  评论(0编辑  收藏  举报