其他分享
首页 > 其他分享> > 【整数哈希】 poj1840 Eqs

【整数哈希】 poj1840 Eqs

作者:互联网

题目来源:poj 1840

参考:https://blog.csdn.net/lyy289065406/article/details/6647387

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
short hashTable[25000001]; //hash[sum]表示值等于sum的解的个数
int main()
{
    int a1, a2, a3, a4, a5;
    while (scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5) == 5)
    {
        memset(hashTable, 0, sizeof(hashTable));
        for (int x1 = -50; x1 <= 50; x1++)
        {
            if (!x1)
                continue;

            for (int x2 = -50; x2 <= 50; x2++)
            {
                if (!x2)
                    continue;
                int sum = (a1 * x1 * x1 * x1 + a2 * x2 * x2 * x2) * (-1);
                if (sum < 0)
                    sum += 25000000;
                hashTable[sum]++;
            }
        }

        int solution = 0;

        for (int x3 = -50; x3 <= 50; x3++)
        {
            if (!x3)
                continue;
            for (int x4 = -50; x4 <= 50; x4++)
            {
                if (!x4)
                    continue;
                for (int x5 = -50; x5 <= 50; x5++)
                {
                    if (!x5)
                        continue;
                    int sum = a3 * x3 * x3 * x3 + a4 * x4 * x4 * x4 + a5 * x5 * x5 * x5;
                    if (sum < 0)
                        sum += 25000000;
                    if (hashTable[sum])
                        solution += hashTable[sum];
                }
            }
        }
        cout << solution << endl;
    }
    return 0;
}

标签:int,Eqs,d%,a1,hashTable,哈希,include,sum,poj1840
来源: https://blog.csdn.net/qq_39504764/article/details/94408481