HDU 1496 Equations

http://acm.hdu.edu.cn/showproblem.php?pid=1496

今天刚知道这种方法叫哈希。。。开始没考虑清楚边界,各种错,A了再看也就那么回事

View Code
#include <stdio.h>

#include <string.h>

const int N=1000000;

int hash[2000001];

int main()

{

    int a,b,c,d;

    int ans;

    int i,j;

    while(~scanf("%d%d%d%d",&a,&b,&c,&d))

    {

        if((a>0&&b>0&&c>0&&d>0)||(a<0&&b<0&&c<0&&d<0))

        {

            printf("0\n");

            continue;

        }

        ans=0;

        memset(hash,0,sizeof(hash));

        for(i=1;i<=100;i++)

            for(j=1;j<=100;j++)

                hash[N+a*i*i+b*j*j]++;

        for(i=1;i<=100;i++)

            for(j=1;j<=100;j++)

                ans+=hash[N-c*i*i-d*j*j];

        printf("%d\n",ans*16);

    }

    return 0;

} 

 

你可能感兴趣的:(HDU)