Description

Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=
The coefficients are given integers from the interval [-,].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-,], xi != , any i∈{,,,,}. Determine how many solutions satisfy the given equation.
Input The only line of input contains the 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 Sample Output

题目

  

  芒果君:这道题是裸暴力,但是今天我们有一个新的思路,就是用哈希来优化暴力。我们把五项i=1->5 表示为Xi,那么很明显X1+X2+X3==-X4-X5,这样我们把等式左边存到哈希表,然后让等式右边去找左边,大大减小了枚举的时间复杂度。

  

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define mod 100003
#define ll long long
using namespace std;
int hl[mod],a1,a2,a3,a4,a5,cnt,ans;
int cal(int x){return x*x*x;}
struct H{
int val,ne;
}Hash[];
void insert(int x)
{
int key=abs(x)%mod;
Hash[++cnt].val=x;
Hash[cnt].ne=hl[key];
hl[key]=cnt;
}
int search(int x)
{
int sum=;
int key=abs(x)%mod;
for(int i=hl[key];i;i=Hash[i].ne) if(Hash[i].val==x) sum++;
return sum;
}
int main()
{
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
for(int i=-;i<=;++i)if(i)
for(int j=-;j<=;++j)if(j)
for(int k=-;k<=;++k)if(k)
insert(a1*cal(i)+a2*cal(j)+a3*cal(k));
for(int i=-;i<=;++i)if(i)
for(int j=-;j<=;++j)if(j)
ans+=search(-a4*cal(i)-a5*cal(j));
printf("%d",ans);
return ;
}

POJ 1840:Eqs的更多相关文章

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

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

  2. 【POJ】1840:Eqs【哈希表】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18299   Accepted: 8933 Description ...

  3. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  4. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  5. poj 1840 Eqs (hash)

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

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

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

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

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

  8. POJ 1840 Eqs

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15010   Accepted: 7366 Description ...

  9. POJ 1840 Eqs 二分+map/hash

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

随机推荐

  1. bootstrap-vue 中 model 基础用法

    Model 官方文档:  https://bootstrap-vue.js.org/docs/components/modal <b-modal v-model="labelModal ...

  2. pyinstaller打包好的.exe程序在别的电脑上运行出错

    打开.exe提示: Failed to execute script... 查看命令行错误提示为: 总的来说呢,就是有的版本pyqt5库对系统变量的加载存在bug,具体原因只有官方才能解释了,咱也没法 ...

  3. vue项目,前端导出excel

    今天研究一下前端如何导出excel,边查边实践,边记录 1.安装依赖库 xlsx:这是一个功能强大的excel处理库,但是上手难度也很大,还涉及不少二进制的东西 file-saver:ES5新增了相关 ...

  4. openpyxl模块(excel操作)

    openpyxl模块介绍 openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读 ...

  5. easyui-textbox输入框数字校验

    输入框数字校验 $("#reg_num").textbox('textbox').bind('keyup', function(e){ $("#reg_num" ...

  6. C#winform如何实现文本编辑框(TextBox)的Hint提示文字效果

    C#winform如何实现文本编辑框(TextBox)的Hint提示文字效果 private const int EM_SETCUEBANNER = 0x1501; [DllImport(" ...

  7. 【Centos】搭建 SVN 服务器

    1.如果仅仅只是搭建 svn 服务器: (a).先检查 svn 是否已经安装了 rpm -qa subversion #输入这个命令后,会出现 subversion 版本号   (b).如果没有安装, ...

  8. linux中怎样会引起进程睡眠呢?

    答: 使用信号量,wait队列,completion,调用schedule,用GFP_KERNEL指定的内存分配malloc,get,free,page等都会引起睡眠 思考: Q: 为什么会引起睡眠呢 ...

  9. appStore上传苹果应用程序软件发布

    首先确定帐号是否能发布, https://developer.apple.com/account,如果你打开Provisioning Portal,然后点击DisTribution(1)图中加号是灰色 ...

  10. create-react-app 工程,如何修改react端口号?

    概要: 3000端口是webpack配置里面写的,可以通过传递一个PORT全局变量,来修改这个端口.当然,您还可以在node_modules/react-scripts/目录下面,批量搜索替换3000 ...