POJ 1840 Eqs [HASH]
2012-04-19 16:28
423 查看
Description
Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
Input
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output
The output will contain on the first line the number of the solutions for the given equation.
Sample Input
Sample Output
View Code
Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
Input
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output
The output will contain on the first line the number of the solutions for the given equation.
Sample Input
37 29 41 43 47
Sample Output
654 code:
View Code
#include<stdio.h> #include<string.h> int abs(int x) { return x>0?x:-x; } struct node { int key,num; }h[200007]; int maxn=200007; int main() { int a[5]; int p[101]; int i,j,k,t1,t2,t3,t4,tt,res; for(i=-50;i<0;i++) p[i+50]=i*i*i; for(i=1;i<=50;i++) p[i+49]=i*i*i; while(scanf("%d",&a[0])!=EOF) { for(i=1;i<5;i++) scanf("%d",&a[i]); memset(h,0,sizeof(h)); for(i=0;i<100;i++) { t1=p[i]*a[0]; for(j=0;j<100;j++) { t2=t1+p[j]*a[1]; tt=abs(t2)%maxn; while(h[tt].num&&h[tt].key!=t2) tt=(tt+1)%maxn; if(h[tt].key==t2) h[tt].num++; else { h[tt].key=t2; h[tt].num++; } } } res=0; for(i=0;i<100;i++) { t1=p[i]*a[2]; for(j=0;j<100;j++) { t2=p[j]*a[3]+t1; for(k=0;k<100;k++) { t3=p[k]*a[4]+t2; tt=abs(t3)%maxn; while(h[tt].num&&h[tt].key!=-t3) tt=(tt+1)%maxn; res+=h[tt].num; } } } printf("%d\n",res); } return 0; }
相关文章推荐
- POJ-1840 Eqs【Hash】
- Eqs - poj 1840(hash)
- poj 1840 Eqs(暴力枚举+hash)
- POJ 1840 Eqs(hash)
- POJ 1840 Eqs(hash)
- poj 1840 Eqs(Hash)
- POJ 1840 Eqs 二分+map/hash
- POJ 1840 Eqs (大整数的Hash)
- HDU_1496 Equations && POJ_1840 Eqs(Hash)
- POJ题目1840 Eqs(hash)
- POJ1840: Eqs(hash问题)
- POJ 1840 Eqs.cpp 【 Hash 】
- POJ 1840 Eqs (Hash)
- poj 1840 Eqs (hash)
- poj 1840 Eqs (Hash)
- Poj 1840 Eqs(Hash)
- POJ 1840 Eqs(hash)
- hdu 题目1496 Equations , POJ 题目1840 Eqs (整数Hash)
- poj-1840 Eqs(hash)
- poj 1840 Eqs , hash