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. 移动web——touch事件应用

    基本概况 1.touch事件在移动端被用来代替click事件,因为click事件的触发会延迟影响了用户体验 2.touch事件还可以与translate构成吸附效果 3.现行有一种排版方式是左边宽度是 ...

  2. java攻城师之路--复习java web之request_respone

    Servlet技术 两条主线1.HTTP协议 2.Servlet生命周期 init() 方法中参数 ServletConfig 对象使用通过ServletConfig 获得 ServletContex ...

  3. [Windows Server 2012] 安装护卫神·主机管理系统

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装护卫神·主 ...

  4. Java中的接口详解

    接口 是Java语言中一种引用类型,是方法的集合,如果说类的内部封装了成员变量.构造方法和成员方法,那么接口的内部主要就是封装了方法,包含抽象方法(JDK 7及以前),默认方法和静态方法(JDK 8) ...

  5. CAD在网页中绘制批注

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  6. 【转载】resolv.conf中search作用

    原文地址:http://www.oliver.ren/linux/387.html reslov.conf中的search主要是用来补全hostname的,有时候域名太长,可以做一个短域名做主机名字, ...

  7. VMware或者KVM克隆的虚拟机网卡无法启动

    在VMware里克隆出来的CentOS Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting ...

  8. WinForm窗体中窗口控件的生成

    1:button控件的生成方式 Button button = new Button(); button.Size = new Size(80, 80); button.Location = new ...

  9. awk 新手入门笔记

    转自:http://www.habadog.com/2011/05/22/awk-freshman-handbook/ awk新手入门笔记 @作者 : habadog@邮箱 : habadog1203 ...

  10. 原型&&原型链一语道破梦中人

    一直对原型和原型链模模糊糊,今天看到一句话,通过这句话再结合我目前对原型和原型链的理解算是让我对原型和原型链有一个更清醒的认识;并且记忆更加深刻; 任何一个对象都有一个隐式原型:__proto__属性 ...