您的位置:首页 > 其它

HDU 1496 Equations(大整数的hash)

2014-11-04 21:49 411 查看
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1496

题目解析: 类似如POJ 1840 不过注意特判0的情况,这种情况很多,不加会超时。

#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const int maxn = 1200000;
int main ()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int a, b, c, d;
int l = -100, r = 100;
while(scanf("%d %d %d %d",&a, &b, &c, &d) != EOF)
{
if(a>0 && b>0 && c>0 && d>0 || a<0 && b<0 && c<0 && d<0)
{
printf("0\n");
continue;
}

map<int, int>Map;

for(int x1 = l; x1 <= r; x1++)
{
if(!x1) continue;
for(int x2 = l; x2 <= r; x2++)
{
if(!x2) continue;

int sum = maxn + -1*(a*x1*x1 + b*x2*x2);

Map[sum]++;
}
}

int ans = 0;
for(int x3 = l; x3 <= r; x3++)
{
if(!x3) continue;
for(int x4 = l; x4 <= r; x4++)
{
if(!x4) continue;

int sum = maxn + c*x3*x3 + d*x4*x4;
ans += Map[sum];
}
}
printf("%d\n", ans);
}
return 0;
}

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