Hdu 1496 Equations (hash)

Source: Internet
Author: User

Number of Solving Equations

The clever hash mainly refers to the size range of a, B, c, and d x.

View Code

# Include <iostream>
# Include <algorithm>
Using namespace std;
Int hash1 [3000005];
Int main ()
{
Int a, B, c, d, x1, x2, x3, x4, ans;
While (~ Scanf ("% d", & a, & B, & c, & d ))
{
If (a> 0 & B> 0 & c> 0 & d> 0 | a <0 & B <0 & c <0 & d <0) // It must be the same number and cannot be resolved. This timeout occurs on the wood.
{
Puts ("0 ");
Continue;
}
Memset (hash1, 0, sizeof (hash1 ));
Ans = 0;
For (x1 = 1; x1 <101; x1 ++) // hash converts a four-fold loop into a double loop, greatly reducing the complexity
For (x2 = 1; x2 <101; x2 ++)
Hash1 [a * x1 * x1 + B * x2 * x2 + 2000000] ++;
For (x3 = 1; x3 <101; x3 ++)
For (x 4 = 1; x 4 <101; x 4 ++)
Ans + = hash1 [(0-(c x 3x3 + d x 4x4) + 2000000];
Ans * = 16;
// Because the difference between positive and negative numbers does not affect the effect of x square, the positive number is enumerated directly, and then multiplied by the 4 power of 2, indicating the combination of positive and negative
Printf ("% d \ n", ans );
}
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.