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

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

按要求模拟即可

hash是个神奇的东西

下方代码注释部分是先三层循环后二层,正文部分是先二层循环后三层。两者都是正解,但是由于list插入比读取慢,先二层更快

 /*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
const int mxn=14997;
list<int>ha[mxn*2];
list<int>::iterator it;
int x,x1,x2,x3,x4,x5;
int ans=0;
int main(){
scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
int i,j,k;
for(i=-50;i<=50;i++)
for(j=-50;j<=50;j++)
for(k=-50;k<=50;k++){
if(i==0||j==0||k==0)continue;
x=i*i*i*x1+j*j*j*x2+k*k*k*x3;
ha[x%mxn+mxn].push_back(x);//hash //x%mxn+mxn保证hash完以后是正数
}
for(i=-50;i<=50;i++)
for(j=-50;j<=50;j++){
if(i==0|j==0)continue;
x=-(i*i*i*x4+j*j*j*x5);
//检查hash
for(it=ha[x%mxn+mxn].begin();it!=ha[x%mxn+mxn].end();it++ ){
if(*it==x)ans++;
}
}
printf("%d",ans);
return 0; }
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
const int mxn=;
list<int>ha[mxn*];
list<int>::iterator it;
int x,x1,x2,x3,x4,x5;
int ans=;
int main(){
scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
int i,j,k;
for(i=-;i<=;i++)
for(j=-;j<=;j++)
{
if(i==||j==)continue;
x=i*i*i*x1+j*j*j*x2;
ha[x%mxn+mxn].push_back(x);//hash //x%mxn+mxn保证hash完以后是正数
}
for(i=-;i<=;i++)
for(j=-;j<=;j++)
for(k=-;k<=;k++){
if(i==|j==||k==)continue;
x=-(i*i*i*x3+j*j*j*x4+k*k*k*x5);
//检查hash
for(it=ha[x%mxn+mxn].begin();it!=ha[x%mxn+mxn].end();it++ ){
if(*it==x)ans++;
}
}
printf("%d",ans);
return ; }

niconiconi

POJ 1840 Eqs的更多相关文章

  1. poj 1840 Eqs (hash)

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

  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 【解五元方程+分治+枚举打表+二分查找所有key 】

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

  4. POJ 1840 Eqs(hash)

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

  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 暴力

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

  7. POJ 1840 Eqs(乱搞)题解

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

  8. POJ 1840:Eqs 哈希求解五元方程

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14169   Accepted: 6972 Description ...

  9. Eqs - poj 1840(hash)

    题意:对于方程:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,有xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 现在给出a1,a2,a3, ...

随机推荐

  1. C#字符串默认值

    using System; class MYTestX { class CT { } class CO { public CT ott; //默认是null public string strx;// ...

  2. Spring Security笔记:登录尝试次数限制

    今天在前面一节的基础之上,再增加一点新内容,默认情况下Spring Security不会对登录错误的尝试次数做限制,也就是说允许暴力尝试,这显然不够安全,下面的内容将带着大家一起学习如何限制登录尝试次 ...

  3. 纯手工搭建JSF开发环境(JSF2.2+maven+weblogic 12c/jboss EAP 6.1+)

    前言: JSF 2.X因为种种原因(我个人觉得主要是因为推出太晚),再加上EJB2之前的设计过于复杂,引起很多开发人员对官方解决方案的反感,即使EJB3后来做了大量改进,国内也很少有人对EJB3感兴趣 ...

  4. 2016shenyang-1002-HDU5893-List wants to travel-树链剖分+线段树维护不同区间段个数

    肯定先无脑树链剖分,然后线段树维护一段区间不同个数,再维护一个左右端点的费用. 线段树更新,pushDown,pushUp的时候要注意考虑链接位置的费用是否相同 还有就是树链剖分操作的时候,维护上一个 ...

  5. 如何在 ie6 中使用 "localStorage"

    好吧,我只是个标题党,ie6 下根本无法使用跟 h5 沾边的 localStorage.今天要向大家介绍的是 ie 特有的 userData 的存储方式,并且对它进行封装,使得不支持 localSto ...

  6. 深入理解python的yield和generator

    原文发表在我的博客主页,转载请注明出处 前言 没有用过的东西,没有深刻理解的东西很难说自己会,而且被别人一问必然破绽百出.虽然之前有接触过python协程的概念,但是只是走马观花,这两天的一次交谈中, ...

  7. 项目分享二:APP 小红点中数字的处理

    小红点,是 APP 中最常见的一个功能,我们先来看一下面的案例,下图中,待评价的商品有 2 个,点击“评价晒单”按钮进行评价后,那么待评价数量应该变成 1,那么这个功能是如何去实现的呢? 一般来说,实 ...

  8. matlab如何建立一个空矩阵,然后往里面赋值

    x=:; y=[]; :length(x) % y=[y;x(i)];%把每一个x都放到Y里,成为一列 y=[y,x(i)];%把每一个x都放到Y里,成为一行 end

  9. 前端框架——BootStrap学习

    BootStrap简单总结下:1.栅格系统,能够很好的同时适应手机端和PC端(及传说中的响应式布局) 2.兼容性好 接下来是对BootStrap学习的一些基础案例总结和回顾: 首先引入:bootstr ...

  10. Cadence Allegro元件封装制作流程

    (本文为转载,原文出处不详) 引言 一个元件封装的制作过程如下图所示.简单来说,首先用户需要制作自己的焊盘库Pads,包括普通焊盘形状Shape Symbol和花焊盘形状Flash Symbol:然后 ...