Poj 1840 EQS (hash)

Source: Internet
Author: User

Address: poj 1840

Sad... During the competition, I always thought that the theorem or mathematical formula was used for derivation .. I have never looked at it carefully .. The data range of each element is only [-50, 50] in the last 5 minutes ]... Forget it .. Even if you see it, you cannot do it .. Because MLE is used, the definition type of the hash array must be defined as short to solve MLE... I cannot come up with this .... No regrets ..

This is to first find the first two for loops and store the results in a hash array. Then perform the next three for loops. If the value is the opposite number, the sum is 0, and then the number of records is recorded.

The Code is as follows:

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include<algorithm>using namespace std;short _hash[25000001];int main(){    int a, b, c, d, e, i, j, k, m, n, s;    while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF)    {        s=0;        memset(_hash,0,sizeof(_hash));        m=25000000;        for(i=-50;i<=50;i++)        {            if(!i)                continue ;            for(j=-50;j<=50;j++)            {                if(!j)                continue ;                n=i*i*i*a+j*j*j*b;                n=-n;                if(n<0)                    n+=m;                _hash[n]++;            }        }        for(i=-50;i<=50;i++)        {            if(!i)                continue ;            for(j=-50;j<=50;j++)            {                if(!j)                continue ;                for(k=-50;k<=50;k++)                {                    if(!k)                    continue ;                    n=i*i*i*c+j*j*j*d+k*k*k*e;                    if(n<0)                    n+=m;                    if(_hash[n])                        s+=_hash[n];                }            }        }        printf("%d\n",s);    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.