# POJ 1840 Eqs（Hash+思维）

poj 1840

## 分析

(a1x31+a2x32)=a3x33+a4x34+a5x35

## 代码

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
const int INF=999999999;
int a1,a2,a3,a4,a5;
int Key=10007;
struct Hash
{
int sum;
int t;
}H[10010][50];
int cnt[10010];
bool  Find(int x,int y)
{
int loc=abs(-a1*x*x*x-a2*y*y*y)%Key;
for(int i=1;i<=cnt[loc];i++)
{
if(H[loc][i].sum==(-a1*x*x*x-a2*y*y*y )){H[loc][i].t++;return 1;}
}
return 0;
}
void Work()
{
int ans=0;
for(int i=-50;i<=50;i++)
{
if(i==0)continue;

for(int j=-50;j<=50;j++)
{
if(j==0)continue;
int loc=abs(-a1*i*i*i-a2*j*j*j)%Key;
if(Find(i,j)==1)continue;
else
{
H[loc][++cnt[loc]].sum=-a1*i*i*i-a2*j*j*j;
H[loc][cnt[loc]].t=1;
}
}
}

for(int i=-50;i<=50;i++)
{
if(i==0)continue;
for(int j=-50;j<=50;j++)
{
if(j==0)continue;
for(int k=-50;k<=50;k++)
{
if(k==0)continue;
int loc=abs(a3*i*i*i+a4*j*j*j+a5*k*k*k)%Key;
//cout<<loc<<endl;
for(int p=1;p<=cnt[loc];p++)
{
if(H[loc][p].sum==(a3*i*i*i+a4*j*j*j+a5*k*k*k))ans+=H[loc][p].t;
}
}
}
}
cout<<ans<<endl;
}
int main()
{
while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)
{
memset(H,0,sizeof(H));
sizeof(cnt,0,sizeof(cnt));
Work();
}
}


#### poj1840Eqs（哈希判重)

2014-08-20 09:28:20

#### poj-1840 Eqs 暴力+哈希

2015-08-17 10:46:28

#### Eqs(POJ--1840

2015-08-11 14:57:44

#### POJ-1840 Eqs 解题报告

2012-03-16 21:58:03

#### POJ 1840 --EQS

2015-07-31 14:29:33

#### POJ 1840 Eqs

2013-08-24 18:29:48

#### POJ 1840 Eqs(hash)

2014-08-20 08:40:10

#### POJ - 1840 A - Eqs

2017-10-26 19:34:49

#### Eqs POJ - 1840

2017-04-19 16:46:24

#### POJ 1840 Eqs

2011-03-10 20:42:00