您的位置:首页 > 其它

poj 1840 Eqs (hash)

2013-08-23 21:15 507 查看
题目:http://poj.org/problem?id=1840

题解:/article/1968897.html 小优姐讲的很好了

#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;

short hash[25000001];
int main()
{
int a1,a2,a3,a4,a5;
int x1,x2,x3,x4,x5;
int sum,ans=0;
cin>>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]++;
}
}
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;
ans+=hash[sum];
}
}
}
cout<<ans<<endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: