poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840
题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的很好了
1 #include<cstdio> 2 #include<string> 3 #include<iostream> 4 #include<cstring> 5 #include<map> 6 using namespace std; 7 8 short hash[25000001]; 9 int main() 10 { 11 int a1,a2,a3,a4,a5; 12 int x1,x2,x3,x4,x5; 13 int sum,ans=0; 14 cin>>a1>>a2>>a3>>a4>>a5; 15 memset(hash,0,sizeof(hash)); 16 for(x1=-50; x1<=50; x1++) 17 { 18 if(!x1) continue; 19 for(x2=-50; x2<=50; x2++) 20 { 21 if(!x2) continue; 22 sum=a1*x1*x1*x1+a2*x2*x2*x2; 23 if(sum<0) 24 sum+=25000000; 25 hash[sum]++; 26 } 27 } 28 for(x3=-50; x3<=50; x3++) 29 { 30 if(!x3) continue; 31 for(x4=-50; x4<=50; x4++) 32 { 33 if(!x4) continue; 34 for(x5=-50; x5<=50; x5++) 35 { 36 if(!x5) continue; 37 sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5; 38 if(sum<0) 39 sum+=25000000; 40 ans+=hash[sum]; 41 } 42 } 43 } 44 cout<<ans<<endl; 45 46 return 0; 47 } 48