Description

Consider equations having the following form:
a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=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
题意很好懂,倘若用暴力写的话明显不行;这道题我大一(现在还是大一)学长出了很多次,当时水平不行,也不懂哈希算法,下学期学了数据结构,学了哈希表,一看
别人的代码就明白了怎么整的了,首先将方程拆分,分成左右两部分,构建一个哈希数组(hash),hash数组里面的位序代表左边的结果,hash数组对应的数字的大小
就代表这个结果的次数,然后右边的结果如果在这哈希数组对应,则 ans=ans+hash【i】
注意:因为位序不能为负数,左边结果的范围为【-50*50*50*50*2,50*50*50*2】将负数变为正数,加上最大值就可以了,右边同样,hash数组过大,用
short 定义
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
short hash[];
int main()
{
int a,b,c,d,e;
int i,j,k;
while(cin>>a>>b>>c>>d>>e)
{
int sum;
//memset(hash,0,sizeof(hash));
for(i=-;i<=;i++)
{
for(j=-;j<=;j++)
{
if(j!=&&i!=)
{
sum=-(a*i*i*i+b*j*j*j);
if(sum<)
sum=sum+;
hash[sum]++;
}
}
}
int ans=;
for(i=-;i<=;i++)
{
for(j=-;j<=;j++)
{
for(k=-;k<=;k++)
{
if(i!=&&j!=&&k!=)
{
sum=c*i*i*i+d*j*j*j+e*k*k*k;
if(sum<)
sum=sum+;
if(hash[sum]>)
ans=ans+hash[sum];
}
}
}
}
cout<<ans<<endl;
}
}

poj 1840(五元三次方程组)的更多相关文章

  1. YTU 2945: 编程:五元向量的运算

    2945: 编程:五元向量的运算 时间限制: 1 Sec  内存限制: 128 MB 提交: 151  解决: 85 题目描述 用习惯了的运算符操作新定义的类对象,这是OO方法给我们带来的便利.下面要 ...

  2. 【Java例题】4.3 3. 使用Gauss消元法求解n元一次方程组的根,

    3. 使用Gauss消元法求解n元一次方程组的根,举例,三元一次方程组:0.729x1+0.81x2+0.9x3=0.6867x1+x2+x3=0.83381.331x1+1.21x2+1.1x3=1 ...

  3. poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 6851 Description ...

  4. POJ 1840:Eqs 哈希求解五元方程

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14169   Accepted: 6972 Description ...

  5. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  6. POJ 1840 HASH

    题目链接:http://poj.org/problem?id=1840 题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1 ...

  7. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

  8. Linux 常用命令十五 用户和组操作命令

    一.创建一个用户 wang@wang:~/workpalce/threading$ sudo useradd -m python # -m创建家目录 wang@wang:~/workpalce/thr ...

  9. 东大OJ-一元三次方程解的个数

    1043: Fixed Point 时间限制: 5 Sec  内存限制: 128 MB 提交: 26  解决: 5 [提交][状态][讨论版] 题目描述 In mathematics, a fixed ...

随机推荐

  1. 使用Jupter Notebook实现简单的神经网络

    参考:http://python.jobbole.com/82208/ 注:1)# %matplotlib inline 注解可以使Jupyter中显示图片 2)注意包的导入方式 一.使用的Pytho ...

  2. Lazarus Reading XML- with TXMLDocument and TXPathVariable

    也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细.这里列举例子是说明在Lazarus/FP ...

  3. logstash windows下添加服务启动管理

    nssm下载链接:http://nssm.cc/release/nssm-2.24.zip

  4. Centos6.6 安装nfs网络文件系统

    一.介绍 nfs网络文件系统的,大部分用在内网文件共享,比如,对集群上传文件做共享,经常用在图片部分,当然数据量大了还是要做分离,做为专门的接口比较好,介绍一下基本安装环境: 1)Cnetos6.6 ...

  5. HDU_1698_Just a Hook_线段树区间更新

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 如何在Android Studio中查看一个类的继承关系呢?

    在面板顶部的工具栏中,找到Navigate,然后在下拉列表中,找到“Type Hierarchy”(快捷键 Ctrl+H),点击.即可在面板右侧出现该类的Hierarchy层级图.

  7. PHP 之ip查询接口

    /** * @param $ip 待查询的ip * @return mixed */ function getIpAddressInfo($ip) { $ipurl = 'http://api.ip1 ...

  8. CAD在网页中如何设置实体闪烁?

    主要用到函数说明: MxDrawXCustomFunction::Mx_TwinkeEnt 闪烁实体.详细说明如下: 参数 说明 McDbObjectId id 被闪烁的实体对象id LONG lCo ...

  9. Maven中更改默认JDK版本

    只要在settings.xml文件中加上如下标签即可.(我这里是默认的1.7版本) <profiles> <profile> <id>jdk-1.7</id& ...

  10. String s="a"+"b"+"c"+"d";创建了几个对象?

    对于如下代码: package reviewTest; /** * @ClassName: StringTest * @Description: 测试String的字符串相加优化 * @author ...