"Turn" hdu-1496-equations: skillfully use hash

Source: Internet
Author: User

It is possible to simplify the equation to a*x1^2+b*x2^2=-(c*x3^2+d*x4^2) first.

And then use a hash table to put the left side of the equation in a two-tiered loop to save the value.

Finally, we find the number of values of the left function with the right side by two loops and accumulate the answer

The specific details of the reference code

#include <iostream> #include <cstring> #include <cstdio>using namespace std;const int Size = 50*100*100        The first two largest values of the *2;//equation are int hash[2*size+10];int main () {int A, B, C, D;        int arr[101]; for (int i=1; i<101; i++) arr[i]=i*i;//xi^2 This also includes the-I while (cin>>a>>b>>c>& GT;D) {if (a>0&&b>0&&c>0&&d>0) | | |                (a<0&&b<0&&c<0&&d<0))                        {cout<<0<<endl;                Continue                 } memset (hash, 0, sizeof (hash)); for (int i=1, i<101; i++) for (int j=1; j<101; j + +) hash[a*arr[i]+b*arr[                 j]+1000000]++;                 int ans=0; for (int i=1, i<101; i++) for (int j=1; j<101; j + +) ans+=hash[-(C*arr[i]           +D*ARR[J]) +1000000];      cout<< (ans<<4) <<endl;//because for each xi^2 Xi has positive and negative values so the total outcome scheme should be multiplied by 2^4} return 0 on the above basis;} 

  

"Turn" hdu-1496-equations: skillfully use hash

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.