hdu 1496 Equations
2012-09-04 12:26
267 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1496
上一题hash的升级版,不过还是简单题..只能当作是练手了...
View Code
——written by Lyon
上一题hash的升级版,不过还是简单题..只能当作是练手了...
View Code
#include <cstdio> #include <cstring> #include <cstdlib> const int maxn = 50007; int hash[maxn], cnt[maxn]; int tx[101]; void pre(){ for (int i = 1; i <= 100; i++){ tx[i] = i * i; } } void init(){ memset(cnt, 0, sizeof(cnt)); } void insert(int a){ int p = (a << 3) % maxn; if (p < 0) p += maxn; while (hash[p] != a && cnt[p]) p = (p + 1) % maxn; hash[p] = a; cnt[p]++; } int count(int a){ int p = (a << 3) % maxn; if (p < 0) p += maxn; while (hash[p] != a && cnt[p]) p = (p + 1) % maxn; return cnt[p]; } int main(){ int a, b, c, d; pre(); while (~scanf("%d%d%d%d", &a, &b, &c, &d)){ init(); if ((a < 0 && b < 0 && c < 0 && d < 0) || (a > 0 && b > 0 && c > 0 && d > 0)){ puts("0"); continue; } for (int i = 1; i <= 100; i++){ for (int j = 1; j <= 100; j++){ insert(a * tx[i] + b * tx[j]); } } int tt = 0; for (int i = 1; i <= 100; i++){ for (int j = 1; j <= 100; j++){ tt += count(- (c * tx[i] + d * tx[j])); } } printf("%d\n", tt << 4); } return 0; }
——written by Lyon
相关文章推荐
- hdu_1496_equations( 二分 or hash )
- HDU 1496 Equations
- hdu 1496 -- Equations
- HDU 1496 Equations
- hdu 1496 -- Equations(哈希)
- hdu 1496 Equations (整数Hash)
- hdu 1496 equations(哈希)
- HDU 1496 Equations
- (HDU - 1496)Equations
- HDU 1496 Equations(hash or 二分)
- HDU 1496 Equations(哈希表)
- HDU 1496 Equations (hash)
- hdu 题目1496 Equations , POJ 题目1840 Eqs (整数Hash)
- hdu 1496 Equations(hash)@
- HDU 1496 Equations(哈希打表+二分暴力)
- HDU_1496 Equations && POJ_1840 Eqs(Hash)
- hdu 1496 Equations(hash备忘)
- HDU 1496 Equations[HASH]
- hdu1496—Equations(枚举)
- HDU 1496 Equations 哈希