思路:a1x1^3+ a2x2^3+ a3x3^3 = -(a4x4^3 + a5x5^3) 先求出右边能到达的值,对值进行hash,然后左边查询计数,这样比相反的顺序内存少用好多,时间也快不少 #includestdio.h#includestdlib.h#includes
思路:a1x1^3+ a2x2^3+ a3x3^3 = -(a4x4^3 + a5x5^3)
先求出右边能到达的值,对值进行hash,然后左边查询计数,这样比相反的顺序内存少用好多,时间也快不少
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define inf 20003
int Max(int a,int b){
return a>b?a:b;
}
int Min(int a,int b){
return a>b?b:a;
}
int head[20010],res,cnt;
struct point{
int real;
int num;
int next;
}edge[20010];
void add(int tem){
int hash=tem%inf;
if(hash<0)
hash+=inf;
for(int i=head[hash];i!=-1;i=edge[i].next){
if(tem==edge[i].real){
edge[i].num++;
return;
}
}
edge[cnt].real=tem;
edge[cnt].num=1;
edge[cnt].next=head[hash];
head[hash]=cnt++;
}
int query(int tem){
int hash=tem%inf;
if(hash<0)
hash+=inf;
for(int i=head[hash];i!=-1;i=edge[i].next){
if(tem==edge[i].real){
return edge[i].num;
}
}
return 0;
}
int main(){
int i,j,k;
int a1,a2,a3,a4,a5;
scanf("%d %d %d %d %d",&a1,&a2,&a3,&a4,&a5);
memset(head,-1,sizeof(head));
for(i=-50;i<=50;i++)
if(i!=0)
for(j=-50;j<=50;j++)
if(j!=0){
int tem=a4*i*i*i+a5*j*j*j;
add(tem);
}
int sum=0;
for(i=-50;i<=50;i++)
if(i!=0)
for(j=-50;j<=50;j++)
if(j!=0)
for(k=-50;k<=50;k++)
if(k!=0){
int tem=a1*i*i*i+a2*j*j*j+a3*k*k*k;
sum+=query(-tem);
}
printf("%d\n",sum);
return 0;
}