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. 004_STM32程序移植之_SHTXX

    1. 测试环境:STM32C8T6 2. 测试模块:DS1302时钟模块 3. 测试接口: SHTXX土壤温湿度: VCC------------------3.3V GND------------- ...

  2. appium测试android环境搭建(win7)

    第一步:安装appium 1. 下载并安装Node.js(地址:https://nodejs.org/download/) 2. 下载git, 并且配置环境变量:(之前没有配置git, 报错找不到gi ...

  3. js中4种遍历语法比较

    前言:本文主要比较for.for-in.forEach和for-of的异同以及优缺点. for for循环是最原始最易理解的循环遍历方式 for(var index = 0;index < ar ...

  4. thinphp5.1 使用redis作为缓存

    tp自带的cache类支持redis方式.但是 只有string类型.显然不符合我们的日常的业务需求. so.通过查看源码,发现 handler方法.代码见下图 所以, 这样就能用hash list等 ...

  5. nodejs基础(回调函数、模块、事件、文件读写、目录的创建与删除)

    node官网:http://nodejs.cn/ 今天想看看node的视频,对node进一步了解, 1.我们可以从官网下载node到自己的电脑上,今天了解到node的真正概念,node时javascr ...

  6. speech-to-text-wavenet

    docker pull buriburisuri/speech-to-text-wavenet docker run -it buriburisuri/speech-to-text-wavenet p ...

  7. scrapy框架之shell

    scrapy shell scrapy shell是一个交互式shell,您可以在其中快速调试 scrape 代码,而不必运行spider.它本来是用来测试数据提取代码的,但实际上您可以使用它来测试任 ...

  8. StringBuffer中delete与setLength清空字符串效率比较

    问题: StringBuffer中有delete.setLength两个方法可以快速清空字符数组.哪个效率高呢? 结论:从清空字符串角度看,两者效率都很高,比较来看,setLength效率更高. 分析 ...

  9. HearthBuddy Ai 调试实战2 在使用海巨人的时候,少召唤了一个图腾(费用是对的)

    问题 游戏面板 8是青玉之爪13是海巨人17是恐狼前锋 64是萨满 66是圣骑士63,99,46,是微型木乃伊[其中99和46都是2血3攻,63是2血1攻]57是鱼人木乃伊 微型木乃伊 "L ...

  10. 会声会影x7 每次安装均会提示:已安装这个产品的另一个版本

    会声会影x7 每次安装均会提示:已安装这个产品的另一个版本 卸载C++2008 的库就行了 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论