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 ...
随机推荐
- python原生操作mysql
import pymysql HOST = '127.0.0.1' PORT = 3306 USER = 'root' PASSWD = ' DB = 'test' CHARSET = 'utf8' ...
- Educational Codeforces Round 72 (Rated for Div. 2) A题
Problem Description: You play your favourite game yet another time. You chose the character you didn ...
- 010_STM32程序移植之_lib库建立
STM32之lib库建立 1. 测试环境:STM32C8T6 2. 测试接口: 3.串口使用串口一,波特率9600 单片机引脚------------CH340引脚 VCC-------------- ...
- MongoDB-查询关键字/排序等
查询关键字 并列查询$and # 条件都成立才可以查询到结果 db.stutent.find({$and:[{name:"小漩涡"},{age:30}]}) 或查询$or # 有一 ...
- centos6中安装VMware Tools
使用的是centos6.8,其他6版本方法大致相同. 1 .工具/原料1)安装过虚拟机软件的计算机2)linux操作系统 3)虚拟机配置VMware tools文件, 点击工具栏上的[虚拟机],然后选 ...
- GA算法及参数对结果的影响
1.遗传算法简介 遗传算法是一种基于自然选择和群体遗传机理的搜索算法,它模拟了自然选择和自然遗传过程中的繁殖.杂交和突变现象.再利用遗传算法求解问题时,问题的每一个可能解都被编码成一个“染色体”,即个 ...
- np.random.choices的使用
在看莫烦python的RL源码时,他的DDPG记忆库Memory的实现是这样写的: class Memory(object): def __init__(self, capacity, dims): ...
- ArcGIS超级工具SPTOOLS-SHP转数据库,批量数据库转数据库,栅格彩色转黑白
1.1 SHP转数据库 把一个文件夹的数据,转到数据库,或者另一个文件夹,不含字文件夹 1.2 批量数据库转数据库 把一个文件夹下GDB或者MDB,转到另一个文件夹为MDB,GDB,并实现版本的转 ...
- pymysql检查是否断开, 断开重连
python mysql使用持久链接 python链接mysql中没有长链接的概念,但我们可以利用mysql的ping机制,来实现长链接功能~ 思路: 1 python mysql 的cping 函数 ...
- mfc判断当前程序是否正在运行
HANDLE hMutex = CreateMutex(NULL,TRUE,_T("appName")); if(hMutex) { if(ERROR_ALREADY_EXISTS ...