您的位置:首页 > 其它

hdu 1496 Equations

2012-09-04 12:26 267 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1496

  上一题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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: