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;
}
题目解析: 类似如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;
}
相关文章推荐
- HDU 1496 Equations 【整数Hash】
- hdu 1496 Equations (整数Hash)
- hdu 题目1496 Equations , POJ 题目1840 Eqs (整数Hash)
- HDU-1496 Equations [hash]
- hdu 1496 Equations(hash)@
- hdu 1496 整数hash
- HDU 1496 Equations[HASH]
- HDU 1496 Equations (hash)
- hdu_1496_equations( 二分 or hash )
- HDU 1496 Equations hash HDU上排名第一!
- hdu 1496 Equations (双重循环+hash查找)
- HDU 1496 Equations hash HDU上排名第一!
- hdu 1496 Equations(hash备忘)
- hdu 1496 Equations(hash+暴力)
- HDOJ1496 Equations(整数hash)
- hdu 1496 Equations(hash)
- HDU 1496 Equations(hash or 二分)
- Equations(HDU_1496) hash
- hdu 1496 Equations (暴力+hash)
- hdu 1496 Equations ——hash