Hdu 1496 Equations

本文探讨了哈希算法的应用及其在特定条件下的优化策略,通过实例展示了如何利用哈希表进行高效的数据查找和处理。

hash,不会。

CODE:

 

#include <stdio.h>
#include <string.h>

int hash[2000000];
const int N = 1000000;
int p[100];

void init()
{
    for(int i = 1;i <= 100; i++)
        p[i] = i*i;
}

int main()
{
    init();
    int a, b, c, d;
    int i, j;
    while(~scanf("%d%d%d%d", &a, &b, &c, &d))
    {
        if((a > 0 && b > 0 && c > 0 && d > 0) ||

   (a < 0 && b < 0 && c < 0 && d < 0))

        {
            printf("0\n");
            continue;
        } //剪枝
        for(i = 1; i <= 100; i++)
            for(j = 1; j <= 100; j++)
            hash[p[i]*a+p[j]*b+N]++;
        int tot = 0;
        for(i = 1; i <= 100; i++)
            for(j = 1; j <= 100; j++)
             tot += hash[N-p[i]*c-p[j]*d];
        printf("%d\n", tot<<4);           //正负各两种情况
        for(i = 1; i <= 100; i++)             //memset(hash, 0, sizeof(hash));
            for(j = 1; j <= 100; j++)
            hash[p[i]*a+p[j]*b+N]--;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/g0feng/archive/2012/08/29/2662791.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值