https://vjudge.net/problem/POJ-1840
一个五次方程组,问你解的个数是多少个。
系数 -50–50
未知数也是-50–50
直接暴力,时间复杂度在On5,计算100*100*100*100*100,10的10次方,会tle。
一秒1e7。
所以先处理一下。把方程分成两份。左右相等就相加。
注意可能为负数,所以相加一个maxn。
#include <iostream>
#include <cstdio>
#include <cstdlib>
/*简单hash。
*/
using namespace std;
const int maxn=50*50*50*50*5;
short hash1[maxn*2];
int main()
{ int a,b,c,d,e;
while(~scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)){
for(int i=-50;i<=50;i++){
if(!i) continue;
for(int j=-50;j<=50;j++){
if(!j) continue;
for(int x=-50;x<=50;x++){
if(!x) continue;
hash1[maxn+i*i*i*a+j*j*j*b+x*x*x*c]++;
}
}
}
long long ans=0;
for(int i=-50;i<=50;i++){
if(!i) continue;
for(int j=-50;j<=50;j++){
if(!j) continue;
ans+=hash1[maxn-i*i*i*d-j*j*j*e];
}
}
printf("%d\n",ans);
}
return 0;
}