这题做的很搞笑..
真得总结总结..
把方程分成两半,然后计算其中一半,存入hash.
如果枚举另一半,然后与hash表对照..并累加..
可笑的我一开始用了两个大数组来当hash..直接1对1映射累加..然后内存超了..
然后后来才想起来..只用一个hash..然后另一个来找就行了..
但是我用的大数组还是大了..
应该写一个hash才好..
于是怒了..直接map扔上去..- -
#include <iostream>
#include <map>
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
long long result=0;
map<int,int> m;
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int a1,a2,a3,a4,a5;
cin>>a1>>a2>>a3>>a4>>a5;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for (int i=-50;i<=50;i++)
for (int j=-50;j<=50;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i==0||j==0) continue;
int x=i*i*i*a4+j*j*j*a5;
map<int,int>::iterator iter=m.find(x);
if (iter==m.end())
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m.insert(make_pair(x,1));
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
iter->second++;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for (int i=-50;i<=50;i++)
for (int j=-50;j<=50;j++)
for (int k=-50;k<=50;k++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i==0||j==0||k==0) continue;
int x=i*i*i*a1+j*j*j*a2+k*k*k*a3;
map<int,int>::iterator iter=m.find(-x);
if (iter!=m.end())
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
result+=iter->second;
}
}
cout<<result<<endl;
system("pause");
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)