HDU:1496
这题太恶心,被后面的初始化害惨,由于是2000000的数据如果疏忽便会导致超时
#include <stdio.h>
#include <iostream>
int hash[2000001];
int main(void)
{
int a, b, c, d, x, y;
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;
}
int ans = 0;
memset(hash, 0, sizeof(hash));
for (x=1; x<=100; x++)
{
for (y=1; y<=100; y++)
{
hash[a * x * x + b * y * y + 1000000]++;
}
}
for (x=1; x<=100; x++)
{
for (y=1; y<=100; y++)
{
ans += hash[1000000 - (c * x * x + d * y * y)];
}
}
printf("%d/n", 16 * ans);
}
return 0;
}
本文提供了一道HDU 1496题目的解答思路及代码实现,该题目需要通过双重循环遍历计算特定数学表达式的解,并使用哈希表进行计数,最终输出解的数量。
8万+

被折叠的 条评论
为什么被折叠?



