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. 背包系列 hdu 3535 分组背包

    题意: 有n组工作,现在有T分钟时间去做一些工作.每组工作里有m个工作,并且类型为s,s类型可以为0,1,2,分别表示至少选择该组工作的一项,至多选择该工作的一项,不限制选择.每个工作有ci,gi两个 ...

  2. CNN-CV识别简史2012-2017:从 AlexNet、ResNet 到 Mask RCNN

    原文:计算机视觉识别简史:从 AlexNet.ResNet 到 Mask RCNN 总是找不到原文,标记一下.        一切从这里开始:现代物体识别随着ConvNets的发展而发展,这一切始于2 ...

  3. css的基本单词

    <border>边框 border边框 <text>文本 text文本 <indent>缩进 indent缩进 <align>对齐方式 align对齐方 ...

  4. webstrom常用键

    常用快捷键—Webstorm入门指南 提高代码编写效率,离不开快捷键的使用,Webstorm拥有丰富的代码快速编辑功能,你可以自由配置功能快捷键. 快捷键配置 点击“File”-> “setti ...

  5. 黑苹果开启retina,大分辨率的方法

    首先,管理分辨率RDM的软件这里下载: http://pan.baidu.com/s/1bpjL07P 在终端输入: curl -o ~/enable-HiDPI.sh https://raw.git ...

  6. git 缓存密码导致的不能和远程仓库交互unable to access... 403错误

    尝试了各种方式,包括卸载等最终解决方案: 查看本机的credential 是否已经被清空. 如果输入了 git config credential.helper 命令之后没有输出,说明 git 的配置 ...

  7. IO文件读取

    /** *按字节读取文件 */@Testpublic void readerByte() { File file = new File("D:\\BindCheckControllerTes ...

  8. 31.IK分词器配置文件讲解以及自定义词库

    主要知识点: 知道IK默认的配置文件信息 自定义词库     一.ik配置文件     ik配置文件地址:es/plugins/ik/config目录     IKAnalyzer.cfg.xml:用 ...

  9. 17.使用原生cross-fiels技术解决搜索弊端

    主要知识点: 原生cross-fiels的用法 原生cross-fiels解决三个弊端     一.原生cross-fiels的用法     GET /forum/article/_search { ...

  10. Mysql - ORDER BY详解

    0 索引 1 概述 2 索引扫描排序和文件排序简介 3 索引扫描排序执行过程分析 4 文件排序 5 补充说明 6 参考资料 1 概述 MySQL有两种方式可以实现ORDER BY: 1.通过索引扫描生 ...