Address: poj 1840
Sad... During the competition, I always thought that the theorem or mathematical formula was used for derivation .. I have never looked at it carefully .. The data range of each element is only [-50, 50] in the last 5 minutes ]... Forget it .. Even if you see it, you cannot do it .. Because MLE is used, the definition type of the hash array must be defined as short to solve MLE... I cannot come up with this .... No regrets ..
This is to first find the first two for loops and store the results in a hash array. Then perform the next three for loops. If the value is the opposite number, the sum is 0, and then the number of records is recorded.
The Code is as follows:
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include<algorithm>using namespace std;short _hash[25000001];int main(){ int a, b, c, d, e, i, j, k, m, n, s; while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF) { s=0; memset(_hash,0,sizeof(_hash)); m=25000000; for(i=-50;i<=50;i++) { if(!i) continue ; for(j=-50;j<=50;j++) { if(!j) continue ; n=i*i*i*a+j*j*j*b; n=-n; if(n<0) n+=m; _hash[n]++; } } for(i=-50;i<=50;i++) { if(!i) continue ; for(j=-50;j<=50;j++) { if(!j) continue ; for(k=-50;k<=50;k++) { if(!k) continue ; n=i*i*i*c+j*j*j*d+k*k*k*e; if(n<0) n+=m; if(_hash[n]) s+=_hash[n]; } } } printf("%d\n",s); } return 0;}