hdu 1496 哈希

View Code
#include<cstdio>
#include<cstring>
int hash[2000010];
int main()
{
int a,b,c,d,i,j;
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) )//不加TLE
{ printf("0\n");
continue;
}
memset(hash,0,sizeof(hash));
for(i=1;i<=100;i++)
{
for(j=1;j<=100;j++)
{
hash[i*i*a+j*j*b+1000000]++;
}
}
int ans=0;
for(i=1;i<=100;i++)
{
for(j=1;j<=100;j++)
ans+=hash[-(c*i*i+d*j*j)+1000000];
}
printf("%d\n",ans*16);//每个数都可以取正负
}
}

开大空间就好,记录一下

posted @ 2012-03-25 04:15  Because Of You  Views(322)  Comments(0Edit  收藏  举报