HDU 1496 Equations 哈希
2016-12-31 11:12
316 查看
传送门:HDU 1496 Equations
分析:
打表平方数,分正负两组分别哈希。
代码如下:
分析:
打表平方数,分正负两组分别哈希。
代码如下:
#include <stdio.h> #include <string.h> const int MAXN = 50*100*100*2 + 5; int hash_pos[MAXN]; int hash_neg[MAXN]; int pf[101]; int main() { int a,b,c,d,i,j,cnt,tmp; for(i=1; i<101; i++) // 预先打好平方表 pf[i] = i*i; 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; } memset(hash_pos,0,sizeof(hash_pos) memset(hash_neg,0,sizeof(hash_neg)); cnt = 0; for(i=1; i<101; i++) { for(j=1; j<101; j++) { tmp = a*pf[i] + b*pf[j]; tmp < 0 ? hash_neg[-tmp]++ : hash_pos[tmp]++; // 0赋在pos数组 } } for(i=1; i<101; i++) { for(j=1; j<101; j++) { tmp = c*pf[i] + d*pf[j]; cnt += (tmp > 0 ? hash_neg[tmp] : hash_pos[-tmp]); // 0取的时候也要从pos数组中取 } } printf("%d\n",cnt<<4); } return 0; }
相关文章推荐
- HDU 1496 Equations(简单哈希)
- hdu 1496 equations(哈希)
- HDU 1496 Equations(哈希打表+二分暴力)
- hdu 1496 -- Equations(哈希)
- hdu 1496 Equations (双重循环+hash查找)
- hdu 1496 Equations(哈希表)
- HDU-1496 Equations [hash]
- hdu 1496 Equations(hash备忘)
- hdu 1496 Equations 数论
- hdu 1496 Equations (整数Hash)
- hdu 1496 Equations
- hdu 1496 二分或者哈希
- HDU 4334 Trouble 和 HDU 1496 Equations( hash)
- hdu 1496 Equations(hash+暴力)
- HDU 1496 Equations(hash)
- hdu_1496_equations( 二分 or hash )
- HDU 1496 Equations hash HDU上排名第一!
- hdu 1496 Equations
- Equations(HDU_1496) hash
- HDU 1496 Equations[HASH]