poj 1840 Eqs
2014-07-23 19:47
246 查看
Eqs
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
题目意思:
给你a1 , a2 , a3 , a4 , a5 求方程a1x13+ a2x23+
a3x33+ a4x43+
a5x53=0
的解的个数 已知 x1 x2 x3 x4 x5 都不等于 0
若是直接用暴力来写的话,100的五次方肯定会T掉,所以先求前三个a1x13+ a2x23+
a3x33
的值用数组a[100008][100]存起来 (这里为什么是100008因为mod100007)(还有就是为什么是100最开始写的是10导致一直WA原因就是10可能不够存mod值相同的个数)
用数组top[100008]表示哈希%mod之后的值的个数
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 11861 | Accepted: 5808 |
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
题目意思:
给你a1 , a2 , a3 , a4 , a5 求方程a1x13+ a2x23+
a3x33+ a4x43+
a5x53=0
的解的个数 已知 x1 x2 x3 x4 x5 都不等于 0
若是直接用暴力来写的话,100的五次方肯定会T掉,所以先求前三个a1x13+ a2x23+
a3x33
的值用数组a[100008][100]存起来 (这里为什么是100008因为mod100007)(还有就是为什么是100最开始写的是10导致一直WA原因就是10可能不够存mod值相同的个数)
用数组top[100008]表示哈希%mod之后的值的个数
#include<iostream> #define mod 100007; #include<cstring> int a[100008][100]; int top[100008]; using namespace std; int main () { int a1,a2,a3,a4,a5; int x1,x2,x3,x4,x5; int sum1,sum2; int ans=0; memset(top,0,sizeof(top)); cin>>a1>>a2>>a3>>a4>>a5; for(x1=-50;x1<=50;x1++) { if(x1==0) continue; for(x2=-50;x2<=50;x2++) { if(x2==0) continue; for(int x3=-50;x3<=50;x3++) { if(x3==0) continue; sum1=a1*x1*x1*x1+a2*x2*x2*x2+a3*x3*x3*x3; int p=sum1; p=p%mod; if(p<0) p+=mod; a[p][top[p]++]=sum1; } } } for(x4=-50;x4<=50;x4++) { if(x4==0) continue; for(x5=-50;x5<=50;x5++) { if(x5==0) continue; sum2=-a4*x4*x4*x4-a5*x5*x5*x5; int p=sum2; p=p%mod; if(p<0) p+=mod; for(int i=0;i<top[p];i++) { if(a[p][i]==sum2) ans++; } } } cout<<ans<<endl; }
相关文章推荐
- HDU-1496-Equations && POJ-1840-Eqs (hash)
- POJ 1840 Eqs
- poj 1840 Eqs(暴力枚举+hash)
- HDU_1496 Equations && POJ_1840 Eqs(Hash)
- poj-1840 Eqs
- POJ 1840Eqs(hash)
- poj 1840 Eqs
- POJ-1840-Eqs
- POJ 1840 Eqs(哈希)
- POJ 1840 Eqs
- Eqs POJ - 1840
- POJ 1840:Eqs 哈希求解五元方程
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
- poj-1840 Eqs 暴力+哈希
- POJ训练计划1840_Eqs(二分)
- POJ 1840 Eqs
- POJ-1840 Eqs【Hash】
- POJ 1840 Eqs 二分+map/hash
- POJ1840___Eqs(哈希表)
- POJ-1840 Eqs Hash