hdu 1496 equations(哈希)

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

 

题意:

给出 a b c d 的值

求出满足公式 a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 

 的排列数

 

思路:

将公式化为 a*x1^2+b*x2^2=-c*x3^2+-d*x4^2

哈希求左式的值

再哈希右式 并加上对应的值  t=(upper_bound(num1,num1+coun,-temp)-lower_bound(num1,num1+coun,-temp))

累加出ans

 

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<iostream>

#include<algorithm>

using namespace std;

int num1[12000];

int main()

{

    int a,b,c,d,i,j;

    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)

    {

        if(a>0&&b>0&&c>0&&d>0||a<0&&b<0&&c<0&&d<0) {printf("0\n");continue;}       

        int coun=0;

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

        {

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

            {

                num1[coun++]=a*i*i+b*j*j;

            }

        }

        sort(num1,num1+coun);

        int cnt=0;

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

        {

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

            {

                int t;

                int temp=c*i*i+d*j*j;

                if(t=(upper_bound(num1,num1+coun,-temp)-lower_bound(num1,num1+coun,-temp)))

                cnt+=t;

            }

        }

        printf("%d\n",cnt*16);//*2*2*2

    }

    return 0;

}

  

 

你可能感兴趣的:(HDU)