D - Eqs解题报告

原创 2012年03月25日 18:19:21

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
#include<iostream>
using namespace std;
short hash[25000001];  //hash[sum]表示值等于sum的的解的个数(多对1映射)
int main(void)
{
      int a1,a2,a3,a4,a5;  //系数
      while(cin>>a1>>a2>>a3>>a4>>a5)
      {
           memset(hash,0,sizeof(hash));
           for(int x1=-50;x1<=50;x1++)
           {
                 if(!x1)            //x不为0;
                      continue;
                 for(int x2=-50;x2<=50;x2++)
                 {
                      if(!x2)      //x不为0;
                            continue;
                      int sum=(a1*x1*x1*x1+a2*x2*x2*x2)*(-1);  //计算前两项的和,-
                      if(sum<0)   //50*50^3+50*50^3=12500000,由于sum也可能为负数,
                            sum+=25000000;//当sum<0时,我们令sum+=25000000存储到hash[]
                      hash[sum]++;
                 }
           }
           int solution=0;
           for(int x3=-50;x3<=50;x3++)
           {
                 if(!x3)          //x不为0;
                     continue;
                 for(int x4=-50;x4<=50;x4++)
                 {
                      if(!x4)        //x不为0;
                            continue;
                      for(int x5=-50;x5<=50;x5++)
                      {
                            if(!x5)   //x不为0;
                                  continue;
                            int sum=a3*x3*x3*x3 + a4*x4*x4*x4 + a5*x5*x5*x5;  //计算后三项的和();
                           if(sum<0)
                                 sum+=25000000;
                            if(hash[sum])
                                  solution+=hash[sum];//对于方程左边,当x1=m  ,  
                                          //之所以是记录“次数”,而不是记录“是否已出现”,
                      }
                 }
           }
           cout<<solution<<endl;
      }                     
      return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

D - Eqs解题报告(黄杰)

D - Eqs Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su...

POJ-1804 Eqs 解题报告

Description Consider equations having the following form:  a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0  ...

POJ - 1840 Eqs解题报告

题目大意:对于给定的a1,a2,a3,a4,a5[-50,50]。让你求出方程a1·x1^3+a2·x2^3+a3·x3^3+a4·x4^3+a5·x5^3=0的解([-50,50]范围内)的个数。

POJ-1840 Eqs 解题报告

Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 T...

Codeforces Round #281 (Div. 2) 解题报告 A.B.C.D.

A - Vasya and Football 纯模拟。。比较坑的是会有不符合足球常识的地方。。 代码如下: #include #include #include #include #in...

Codeforces Round #274 (Div. 2) 解题报告 (C D E)

C. Exams 思路:tan

codeforces Round #238(div2) d解题报告

D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input ...

解题报告:D - 小Z的袜子(hose) HYSBZ - 2038 莫队算法

题目链接 这题为莫队亲自出的莫队算法的练习题,必做的题,写下来记录一下莫队算法以便自己以后进行查看。 莫队算法可以用来解决静态离线的区间查询问题。 莫队算法的关键在于 已知[L,R]区间的情况下,能否...

谷歌中国算法比赛解题报告 APAC2016D

Problem A. Dynamic Grid Problem B. gBalloon Problem C. IP Address Summarization Problem D...

Codeforces Round #235 (Div. 2) D. Roman and Numbers 解题报告(状态压缩)

D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes ...
  • kbdwo
  • kbdwo
  • 2014-03-11 15:39
  • 950
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)