Topic Meaning:
http://acm.hdu.edu.cn/showproblem.php?pid=1496
For the equation a*x1^2+b*x2^2+c*x3^2+d*x4^2=0, give a,b,c,d, find out how many methods make the equation set up, xi!=0, belong to [-100,100]
A,b,c,d is also not 0, belonging to [ -50,50].
Sample Input
1 2 3-41 1 1 1
Sample Output
390880
Topic Analysis:
Direct violence words, will 100^4,, timeout, we can convert the equation into a*x1^2+b*x2^2=-(c*x3^2+d*x4^2), in the event of violence, the time will become O (100^2), only need to record the left value of the scheme, in the right side of the traversal will appear , pay attention to negative numbers, and there is ai^2. Because the i*i is definitely positive, the range is [-100,100], for each xi^2 there are two states, for four variables therefore will be more 2^4 times the state.
AC Code:
/** * @xiaoran * Violent +hash * The equivalence is divided into two sides to compare, the great God this +100w is very good ah */#include <iostream> #include <cstdio> #include < map> #include <cstring> #include <string> #include <algorithm> #include <queue> #include < vector> #include <stack> #include <cstdlib> #include <cctype> #include <cmath> #define LL Long Longusing namespace Std;int hash[2000010];//note positive or negative int main () {int a,b,c,d; while (cin>>a>>b>>c>>d) {if (a>0&&b>0&&c>0&&d>0) {// A positive sum cannot equal 0 cout<< "0" <<endl; Continue } memset (Hash,0,sizeof (hash)); for (int i=1;i<=100;i++) {for (int j=1;j<=100;j++) {hash[a*i*i+b*j*j+1000000]++;//records arrive at the number of this state , plus 100W guaranteed to be positive}} int ans=0; for (int i=1;i<=100;i++) {for (int j=1;j<=100;j++) {ans+=hash[-c*i*i-d*j*j+1000000];//plus arrives at this shape The number of States}}//Becauseis I*i, the range is [-100,100], for each xi^2 there are two states, so will be more 2^4 times the state cout<<16*ans<<endl; }return 0;}
HDU 1496 equations (violent +hash)