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

Description

Consider equations having the following form: 
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=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

Source

Romania OI 2002

Solution

一开始以为是meet in the middle搜索.....

然而完全没有那么复杂,甚至还可以用暴力map过??

学习了一波hash表!

其实和建边的邻接表很像,就是把某些值系在某个特定的节点上,一般是定一个不大不小的模数来确定位置。

当然可能有重复,不过这就是hash表嘛!接在一起,查询就很接近$O(1)$了。

主要程序:

加入

void add(int v) {
int x = v > 0 ? v : -v;
x = (x % mod + x / mod) % mod;
Edge[++stot] = Node(v, h[x]);
h[x] = stot;
}

查询

int find(int v) {
int ans = 0;
int x = v > 0 ? v : -v;
x = (x % mod + x / mod) % mod;
for(int i = h[x]; i; i = Edge[i].nex)
if(Edge[i].v == v) ans ++;
return ans;
}

很像邻接表吧~

mod是自己定的,这里定的100007,加入或查询都是按固定的mod方案就能固定位置了

#include<iostream>
#include<cstdio>
#define mod 1000007
using namespace std; struct Node {
int v, nex;
Node() { }
Node(int v, int nex) :
v(v), nex(nex) { }
} Edge[]; int stot, h[];
void add(int v) {
int x = v > ? v : -v;
x = (x % mod + x / mod) % mod;
Edge[++stot] = Node(v, h[x]);
h[x] = stot;
} int find(int v) {
int ans = ;
int x = v > ? v : -v;
x = (x % mod + x / mod) % mod;
for(int i = h[x]; i; i = Edge[i].nex)
if(Edge[i].v == v) ans ++;
return ans;
} int main() {
int a1, a2, a3, a4, a5;
scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5);
for(int x1 = -; x1 <= ; x1 ++) if(x1)
for(int x2 = -; x2 <= ; x2 ++) if(x2) {
int s = x1 * x1 * x1 * a1 + x2 * x2 * x2 * a2;
add(s);
}
int ans = ;
for(int x3 = -; x3 <= ; x3 ++) if(x3)
for(int x4 = -; x4 <= ; x4 ++) if(x4)
for(int x5 = -; x5 <= ; x5 ++) if(x5) {
int s = x3 * x3 * x3 * a3 + x4 * x4 * x4 * a4 + x5 * x5 * x5 * a5;
ans += find(s);
}
printf("%d", ans);
return ;
}

【POJ】1840:Eqs【哈希表】的更多相关文章

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

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

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

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

  3. poj 1840 Eqs (hash)

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

  4. POJ 1840 Eqs

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

  5. POJ 1840 Eqs 二分+map/hash

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

  6. POJ 1840 Eqs(hash)

    题意  输入a1,a2,a3,a4,a5  求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立   a,x取值在-50到50之间 直接暴力的话肯定会超时的   100的五次方  10e了都 ...

  7. POJ 1840 Eqs 暴力

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

  8. POJ 1840 Eqs(乱搞)题解

    思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...

  9. POJ 2785 4 Values whose Sum is 0(哈希表)

    [题目链接] http://poj.org/problem?id=2785 [题目大意] 给出四个数组,从每个数组中选出一个数,使得四个数相加为0,求方案数 [题解] 将a+b存入哈希表,反查-c-d ...

  10. POJ 3349 Snowflake Snow Snowflakes (哈希表)

    题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...

随机推荐

  1. ORACLE表空间查询和管理【转】

    红色是自由指定的~~--查询表空间SELECT D.TABLESPACE_NAME,       SPACE "SUM_SPACE(M)",       SPACE - NVL(F ...

  2. 新浪的wap网站,发现原来我们的head存在着这样的差异

    前一段时间一直被wap网站的自适应困惑…… 仔细研究了一下新浪的wap网站,发现原来我们的head存在着这样的差异…… <%@page contentType="text/html;c ...

  3. 【Android开发日记】之入门篇(五)——Android四大组件之Service

    这几天忙着驾校考试,连电脑都碰不到了,今天总算告一段落了~~Service作为Android的服务组件,默默地在后台为整个程序服务,辅助应用与系统中的其他组件或系统服务进行沟通.它跟Activity的 ...

  4. 激活Win10内置版Linux (ubuntu)

    微软自从14316版本后,就开始原生支持Linux  Bash命令行. 1.首先到系统设置——更新和安全——针对开发人员——选择开发者模式. 2.控制面板→程序和功能→启用或关闭Windows功能,勾 ...

  5. No.17 selenium学习之路之判断与等待

    一.三种等待方式 1.sleep 加载time库.time.sleep() 休眠单位以秒为单位 2.implicitly_wait() 等待页面完全加载完成(左上角转圈结束) 参数为等待时间,等待页面 ...

  6. thinkphp框架if标签条件表达式

    eq 等于neq 不等于gt 大于egt 大于等于lt 小于elt 小于等于

  7. Django基础 - 修改默认SQLite3数据库连接为MySQL

    Django数据库连接默认为SQLite3,打开setting.py可以看到数据库部分的配置如下: DATABASES = { 'default': { 'ENGINE': 'django.db.ba ...

  8. 在SQL中有时候我们需要查看现在正在SQL Server执行的命令

    在SQL中有时候我们需要查看现在正在SQL Server执行的命令.在分析管理器或者Microsoft SQL Server Management Studio中,我们可以在"管理-SQL  ...

  9. OSI & TCP/IP 参考模型

    OSI参考模型的结构 OSI划分七层结构的基本原则 网中各结点都具有相同的层次: 不同结点的同等层具有相同的功能: 同一结点内相邻层之间通过接口通信: 每一层可以使用下层提供的服务,并向其上层提供服务 ...

  10. 适合新手的web开发环境

    学习web开发,环境搭建是必不可少的一个环节.你可以使用wamp一键安装包,或者使用sae.bae.gae这种PaaS平台来部署,或者安装*nix系统在本地部署. 对于一个希望体验LAMP式建站的新手 ...