题目链接:
题目解析: 类似如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;
}