hdu 1496 Equations
http://acm.hdu.edu.cn/showproblem.php?pid=1496
上一题hash的升级版,不过还是简单题..只能当作是练手了...
View Code
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 const int maxn = 50007; 6 int hash[maxn], cnt[maxn]; 7 int tx[101]; 8 9 void pre(){ 10 for (int i = 1; i <= 100; i++){ 11 tx[i] = i * i; 12 } 13 } 14 15 void init(){ 16 memset(cnt, 0, sizeof(cnt)); 17 } 18 19 void insert(int a){ 20 int p = (a << 3) % maxn; 21 22 if (p < 0) p += maxn; 23 while (hash[p] != a && cnt[p]) p = (p + 1) % maxn; 24 hash[p] = a; 25 cnt[p]++; 26 } 27 28 int count(int a){ 29 int p = (a << 3) % maxn; 30 31 if (p < 0) p += maxn; 32 while (hash[p] != a && cnt[p]) p = (p + 1) % maxn; 33 34 return cnt[p]; 35 } 36 37 int main(){ 38 int a, b, c, d; 39 40 pre(); 41 while (~scanf("%d%d%d%d", &a, &b, &c, &d)){ 42 init(); 43 if ((a < 0 && b < 0 && c < 0 && d < 0) || (a > 0 && b > 0 && c > 0 && d > 0)){ 44 puts("0"); 45 continue; 46 } 47 for (int i = 1; i <= 100; i++){ 48 for (int j = 1; j <= 100; j++){ 49 insert(a * tx[i] + b * tx[j]); 50 } 51 } 52 int tt = 0; 53 54 for (int i = 1; i <= 100; i++){ 55 for (int j = 1; j <= 100; j++){ 56 tt += count(- (c * tx[i] + d * tx[j])); 57 } 58 } 59 printf("%d\n", tt << 4); 60 } 61 62 return 0; 63 }
——written by Lyon