POJ 1840 hash
2013-01-31 22:56
281 查看
//11225868 c00h00g 1840 Accepted 24868K 407MS G++ 1083B 2013-01-31 22:52:46 //我自己想的是移过去一项,即a1*x1^3+a2*x2^3+a3*x3^3+a4*x4^3=-a5*x5^3,然后将左边即为x,枚举左边,可以解出x5,然后判断x5是否在范围内 //不过,可能是精度的问题,结果都不正确 //然后看晚上用的都是hash,将算式分成两部分 a1*x1^3+a2*x2^3+a3*x3^3=-(a4*x4^3+a5*x5^3)一开始用左边做hash,但是超内存了,于是用右边 //做hash //还有一点这里的hash不是存在和不存在,而是需要累加的,值相同,但对应的参数是不同的 //这一题有一个bug, while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)不写==5的时候会一直超时 #include<stdio.h> #include<stdlib.h> #include<string.h> const int base=50*50*50*50*2; char hash[2*base+5]; int main(){ int a1,a2,a3,a4,a5,x1,x2,x3,x4,x5; while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)==5){ memset(hash,0,sizeof(hash)); int res=0; for(int x1=-50;x1<=50;x1++) if(x1==0) continue; else for(int x2=-50;x2<=50;x2++) if(x2==0) continue; else hash[a1*x1*x1*x1+a2*x2*x2*x2+base]+=1; for(int x3=-50;x3<=50;x3++) if(x3==0) continue; else for(int x4=-50;x4<=50;x4++) if(x4==0) continue; else for(int x5=-50;x5<=50;x5++) if(x5==0) continue; else{ int x=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5; x*=-1; if(x>=-base&&x<=base&&hash[x+base]) res+=hash[x+base]; } printf("%d\n",res); } return 0; }
相关文章推荐
- POJ - 1840 hash去重
- POJ 1840 - Hash
- POJ - 1840 hash去重
- Eqs - poj 1840(hash)
- POJ - 1840 hash去重
- poj 1186 poj 1840 方程的解数 hash+枚举 (n/2)
- poj 1840 Eqs (Hash)
- poj 1840 Eqs(暴力枚举+hash)
- POJ - 1840 hash去重
- POJ 1840 Eqs [HASH]
- POJ 1840 Hash 链地址避免冲突
- POJ 1840 双向搜索 +Hash
- poj 1840 Eqs(Hash)
- POJ 1840 HASH
- HDU_1496 Equations && POJ_1840 Eqs(Hash)
- POJ - 1840 hash去重
- poj 1840 简单hash。
- POJ 1840 Eqs(hash)
- POJ - 1840 hash去重
- POJ 1840 Eqs (Hash)