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. html5——渐变

    线性渐变 <style> div { width: 700px; height: 100px; /*方向:从右向左*/ /*起始颜色:黄色*/ /*终止颜色:绿色*/ background ...

  2. html5——文本阴影

    基本结构 text-shadow: 30px 23px 31px #;/* 文字阴影: 水平位移 垂直位移 模糊程度 阴影颜色*/ 凹凸文字 <!DOCTYPE html> <htm ...

  3. Windows下环境变量显示、设置或删除操作详情

    显示.设置或删除 cmd.exe 环境变量. SET [variable=[string]] variable 指定环境变量名. string 指定要指派给变量的一系列字符串. 要显示当前环境变量,键 ...

  4. How an SSL connection is established

    An SSL connection between a client and server is set up by a handshake, the goals of which are: To s ...

  5. centos 7 配置nginx

    安装nginx: curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0. ...

  6. python tkinter模块 创建窗口V1.2

    先上图 代码如下 #-*-coding:utf-8-*- import os from tkinter import * root=Tk() root.title('执行窗口') "&quo ...

  7. sysbench测试阿里云CPU

    参考 https://wiki.mikejung.biz/Benchmarking 买了一个1核的ECS,测试一下CPU性能 第一次是只用1个thread去跑 [root@iZwz9fy718twfi ...

  8. vue移动端地址三级联动组件(一)

    vue移动端地区三级联动 省,市,县.用的vue+mintUi 因为多级联动以及地区的规则比较多.正好有时间自己写了一个.有问题以及建议欢迎指出.涉及到dom移动,所以依赖vue+jquery.这边数 ...

  9. auto类型推导

    引言 auto : 类型推导. 在使用c++的时候会经常使用, 就像在考虑STL时迭代器类型, 写模板的时候使用auto能少写代码, 也能帮助我们避免一些隐患的细节. auto初始化 使用auto型别 ...

  10. 升级 Linux 内核版本(编译源代码)

    升级内核版本(自己编译源码) 从 linux 官网 https://www.kernel.org/ 下载内核源码 解压 tar -xvf linux-4.16.8.tar.xz cd linux-4. ...