题意:
给你 a1, a2, a3, a4, a5,的值让你去求几个不同的解,解的范围在-50到50,解不等于0;
思路:
技巧枚举暴力
把方程变一下:
去枚举x1,x2,哈希,然后取枚举x3.x4,x5;
有负数的,需要加上25000000,然后存起来
但是这样的话,仍会MLE,需要把int 变成 short , 这个占2个字节,不会MLE
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
short _hash[25000001];
int main()
{
int x1, x2, x3, x4, x5, a1, a2, a3, a4, a5,sum;
while(~scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5))
{
memset(_hash,0,sizeof(_hash));
for(x1 = -50; x1 <= 50;x1++)
{
if(!x1)
continue;
for(x2 = -50; x2 <= 50; x2++)
{
if(!x2)
continue;
sum = -(a1*x1*x1*x1+a2*x2*x2*x2);
if(sum < 0)
sum+=25000000;
_hash[sum]++;
}
}
int cnt = 0;
for(x3 = -50; x3 <= 50; x3++)
{
if(!x3)
continue;
for(x4 = -50; x4 <= 50; x4++)
{
if(!x4)
continue;
for(x5 = -50; x5 <= 50; x5++)
{
if(!x5)
continue;
sum = a3*x3*x3*x3 + a4*x4*x4*x4 + a5*x5*x5*x5;
if(sum < 0)
sum+=25000000;
if(_hash[sum])
cnt+=_hash[sum];
}
}
}
printf("%d\n",cnt);
}
return 0;
}