HDU 1496 hash+ Violence

Source: Internet
Author: User

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

Problem Descriptionconsider equations having the following form:

A*x1^2+b*x2^2+c*x3^2+d*x4^2=0
A, B, C, D is integers from the interval [ -50,50] and any of them cannot is 0.

It is consider a solution a system (X1,X2,X3,X4) that verifies the equation, Xi is an integer from [ -100,100] and Xi! = 0, any i∈{1,2,3,4}.

Determine how many solutions satisfy the given equation.

Inputthe input consists of several test cases. Each test case consists of a containing the 4 coefficients a, B, C, D, separated by one or more blanks.
End of file.
Outputfor each test case, output a single line containing the number of the solutions.

Sample Input
1 2 3-41 1 1 1

Sample Output
390880
This problem can be enumerated in two points, but the hash is simpler.

We can guarantee that a*i*i, B*j*j,-c*i*i,-d*j*j is a positive integer, so we could use an array to represent the

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;int hash[1000000*2+7];int A,b,c,d;int Main () {    while (~scanf ("%d%d%d%d", &a,&b,&c,&d))    {        memset (hash,0,sizeof (hash));        for (int i=1;i<=100;i++)        {for            (int j=1;j<=100;j++)            {                hash[i*i*a+j*j*b+1000000]++;            }        }        int sum=0;        for (int i=1;i<=100;i++)        {for            (int j=1;j<=100;j++)            {                sum+=hash[-i*i*c-j*j*d+1000000];            }        }        printf ("%d\n", sum*16);    }    return 0;}


HDU 1496 hash+ Violence

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.