poj 1840 Eqs

来源:互联网 发布:网络歌曲主的爱 编辑:程序博客网 时间:2024/06/16 03:36

题目链接:点击打开链接

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

37 29 41 43 47

Sample Output

654
题目大意:给出5元3次方程,求有多少关于x1--x5的不同的解.
直接暴力定会超时,把5元分开,等号两侧有个三元的有个两元的,暴力两元的找出关于x1,x2的所有的解,将x1与x2的和哈希一下,在暴力三元的时候直接哈希找能否使等式两侧成立.
注意数组的开的范围,二元暴力50*50*50*100=1250000,当sum为负数时存在12500000之后的数组中,所以要开25000000
<span style="font-size:18px;">#include <iostream>#include<cstring>using namespace std;short hash[25000001];int sum;int main(){    int a,b,c,d,f;    cin>>a>>b>>c>>d>>f;    memset(hash,0,sizeof(hash));    for(int x1=-50; x1<=50; x1++)    {        if(!x1)continue;        for(int x2=-50; x2<=50; x2++)        {            if(!x2)continue;            sum=(a*x1*x1*x1+b*x2*x2*x2)*(-1);            if(sum<0)                sum+=25000000;            hash[sum]++;        }    }    int ans=0;    for(int x3=-50; x3<=50; x3++)    {        if(!x3)continue;        for(int x4=-50; x4<=50; x4++)        {            if(!x4)continue;            for(int x5=-50; x5<=50; x5++)            {                if(!x5)continue;                sum=c*x3*x3*x3+d*x4*x4*x4+f*x5*x5*x5;                if(sum<0)                    sum+=25000000;                ans+=hash[sum];            }        }    }    cout<<ans<<endl;    return 0;}</span>


0 0
原创粉丝点击