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. [Google Guava] 2.1-不可变集合

    范例 01 public static final ImmutableSet<String> COLOR_NAMES = ImmutableSet.of( 02 "red&quo ...

  2. Consul概述

    环境安装 1.下载consul 官网https://www.consul.io/downloads.html下载对应版本的consul:本文以Windows-64版本为例 2.配置到系统环境变量 C: ...

  3. Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】

    B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...

  4. mysql查看查询缓存是否启用

    查看查询缓存情况: mysql> show variables like '%query_cache%';  (query_cache_type 为 ON 表示已经开启) +---------- ...

  5. Dynamic Data linq to SQL Web Application

    微软提供了一个数据驱动网站模板,可以自动生成CRUD页面,使用过程中碰到些问题 1.首先是如何应用,只需要创建个context并且在Global.asax里面加入下面这一句就可以了 DefaultMo ...

  6. 牛客练习赛53 (E 老瞎眼 pk 小鲜肉) 线段树+离线

    考试的时候切的,类似HH的项链~ code: #include <bits/stdc++.h> #define ll long long #define M 500003 #define ...

  7. Java操作文件那点事

    刚开始学Java时候,一直搞不懂Java里面的io关系,在网上找了很多大多都是给个结构图草草描述也看的不是很懂.而且没有结合到java7 的最新技术,所以自己结合API来整理一下,有错的话请指正,也希 ...

  8. 1626:【例 2】Hankson 的趣味题

    1626:[例 2]Hankson 的趣味题题解 [题目描述] Hanks 博士是 BT(Bio-Tech,生物技术)领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson ...

  9. 代码审计-Typecho反序列化getshell

    0x01 漏洞代码 install.php: <?php $config = unserialize(base64_decode(Typecho_Cookie::get('__typecho_c ...

  10. springboot中web应用的统一异常处理

    在web应用中,请求处理过程中发生异常是非常常见的情况.springboot为我们提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异 ...