POJ 1840:Eqs
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的更多相关文章
- POJ 1840:Eqs 哈希求解五元方程
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14169 Accepted: 6972 Description ...
- 【POJ】1840:Eqs【哈希表】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18299 Accepted: 8933 Description ...
- 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 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 Description ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
随机推荐
- redis在linux服务器部署
0)参考资料 http://www.cnblogs.com/liuling/p/2014-4-19-02.html 1)下载安装包地址 http://download.redis.io/release ...
- 001_Python安装
1. 判断电脑是否已经安装python,电脑->运行->输入:python 2. 如果没有安装,去官网下载:https://www.python.org/downloads/ 3. 安装过 ...
- Dubbo——配置
一.配置原则 JVM 启动 -D 参数优先,这样可以使用户在部署和启动时进行参数重写,比如在启动时需改变协议的端口. XML 次之,如果在 XML 中有配置,则 dubbo.properties 中的 ...
- 关于在eclipse中Undefined attribute name (role).解决办法
方案一: 只需要在jsp表头添加一句: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c&q ...
- codeforces#1234F. Yet Another Substring Reverse(子集dp)
题目链接: https://codeforces.com/contest/1234/problem/F 题意: 给出一个只包含前20个小写字母的字符串,一次操作可以让一段字符颠倒顺序 最多一次这样的操 ...
- win10下linux子系统的文件夹的布局
我这里的目录为:C:\Users\com\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\Loca ...
- Apache Flink - 配置依赖,连接器,库
每个Flink程序都依赖于一组Flink库. 1.Flink核心和应用程序依赖项 Flink本身由一组类和运行需要的依赖组成.所有类和依赖的组合形成了Flink运行时的核心,并且当一个Flink程序运 ...
- zookeeper源码 — 五、处理写请求过程
目录 处理写请求总体过程 客户端发起写请求 follower和leader交互过程 follower发送请求给客户端 处理写请求总体过程 zk为了保证分布式数据一致性,使用ZAB协议,在客户端发起一次 ...
- java客户端验证https连接(忽略证书验证和证书验证两种方式)
首先根据如下操作生成证书,配置springboot https,生成一个简单的https web服务 https://www.cnblogs.com/qq931399960/p/11889349.ht ...
- mod 运算与乘法逆元
mod 运算与乘法逆元 %运算 边乘边mod 乘法 除法 mod 希望计算5/2%7=6 乘法 除法 mod 希望计算5/2%7=6 两边同时/x 在取mod(p)运算下,a/b=a*bp-2 bp- ...