POJ 1840 Eqs(hash)】的更多相关文章

题意  输入a1,a2,a3,a4,a5  求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立   a,x取值在-50到50之间 直接暴力的话肯定会超时的   100的五次方  10e了都    然后能够考虑将等式变一下形   把a1*x1^3+a2*x2^3移到右边   也就是-(a1*x1^3+a2^x2^3)=a3*x3^3+a4*x4^3+a5*x5^3 考虑到a1*x1^3+a2^x2^3的最大值50*50^3+50*50^3=12500000  这个数并不大  能够开这么大…
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的很好了 #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<map> using namespace std; ]; int main() {…
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,…
Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15010   Accepted: 7366 Description Consider equations having the following form:  a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0  The coefficients are given integers from the interval [-50,50].  I…
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0] * pow(x[0], 3) + a[1] * pow(x[1], 3) + a[2] * pow(x[2], 3) + a[3] * pow(x[3], 3) + a[4] * pow(x[4], 3)==0 其中x[i]满足-50<=x[i]<=50,0<=i<5 思路 该等式…
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再找右边是否也能得到就行了,暴力的复杂度从O(n^5)降为O(n^3 + n^2).因为左式范围-12500000~12500000,所以至少开12500000 * 2的空间,用int会爆,这里用short.如果小于0要加25000000,这样不会有重复的答案,算是简单的hash? 代码: #incl…
Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 6851 Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The coefficients are given integers from the interval [-50,50]. It i…
  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∈[-5…
题意:对于方程:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,有xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 现在给出a1,a2,a3,a4,a5的值,求出满足上面方程的解有多少个. 思路:hash的应用.暴力枚举的话会达到100^5,明显会超时.所以将方程分成-(a1x13+ a2x23 )和 a3x33+a4x43+ a5x53 两部分,若这两部分相等,则为方程的一个解. #include<stdio.h> #include&…
题目链接:http://poj.org/problem?id=1840 题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1~x5)的组合使得公式成立.并且(x1~x5)取值再[-50,50]且不能为0 思路:因为x的值范围比较小,只有100.所以可以先求出 a1x1^3+a2x2^3+a3x3^3. 然后在求 (-1)*(a4x4^3+a5x5^3)从前面的所得的Hash表进行二分查找. #include<iostre…