Eqs
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 14093   Accepted: 6927

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

#include<iostream>    49664K   610MS
#include<cstdio>
#include<cstring> using namespace std; short hash[25000001]; //hash[sum]表示值等于sum的的解的个数(多对1映射) int main() //用int会MLE<span id="transmark"></span>
{
int a1,a2,a3,a4,a5; //系数
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
{
memset(hash,0,sizeof(hash));
for(int x1=-50; x1<=50; x1++)
{
if(!x1)
continue;
for(int x2=-50; x2<=50; x2++)
{
if(!x2)
continue;
int sum=(a1*x1*x1*x1+a2*x2*x2*x2);
if(sum<0)
sum+=25000000;
hash[sum]++;
}
}
int num=0;
for(int x3=-50; x3<=50; x3++)
{
if(!x3)
continue;
for(int x4=-50; x4<=50; x4++)
{
if(!x4)
continue;
for(int x5=-50; x5<=50; x5++)
{
if(!x5)
continue;
int sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if(sum>12500000||sum<-12500000) //防止特殊情况发生
continue;
if(sum<0)
sum+=25000000;
if(hash[sum])
num+=hash[sum];
}
}
}
cout<<num<<endl;
}
return 0;
}
#include<iostream>  //  1164K    1704MS
#include<cstdio>
#include<map> using namespace std; int main()
{
map<int,int>Q;
int a,b,c,d,e;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
Q.clear();
for(int i=-50; i<=50; i++)
{
if(!i)
continue;
for(int j=-50; j<=50; j++)
{
if(!j)
continue;
int sum=a*i*i*i+b*j*j*j;
Q[-sum]++;
}
}
int num=0;
for(int i=-50;i<=50;i++)
{
if(!i)
continue;
for(int j=-50;j<=50;j++)
{
if(!j)
continue;
for(int k=-50;k<=50;k++)
{
if(!k)
continue;
int sum=c*i*i*i+d*j*j*j+e*k*k*k;
if(Q.count(sum))
num+=Q[sum];
}
}
}
printf("%d\n",num); }

poj 1840 哈希的更多相关文章

  1. POJ 1840 Eps 解题报告(哈希)

    a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0,xi∈[-50,50],且xi!=0.让我们求所有解的可能. 首先,如果暴力判断的话,每个x的取值有100种可能,100^5肯定 ...

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

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

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

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

  4. POJ 1840 HASH

    题目链接:http://poj.org/problem?id=1840 题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1 ...

  5. poj 1840 Eqs (hash)

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

  6. POJ 1840 Eqs 二分+map/hash

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

  7. POJ 1840 Brainman(逆序对数)

    题目链接:http://poj.org/problem?id=1804 题意:给定一个序列a[],每次只允许交换相邻两个数,最少要交换多少次才能把它变成非递降序列. 思路:题目就是要求逆序对数,我们知 ...

  8. poj 1840(五元三次方程组)

    Description Consider equations having the following form: a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 T ...

  9. POJ 1840:Eqs

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

随机推荐

  1. [POJ] 2223 Muddy Fields

    Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11490 Accepted: 4270 Description Rain has ...

  2. linux系统日志中出现大量systemd Starting Session ### of user root 解决

    这种情况是正常的,不算是一个问题 https://access.redhat.com/solutions/1564823 Environment Red Hat Enterprise Linux 7 ...

  3. (二十二)python 3 sort()与sorted()

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列 一,最简单的排序 1.使用sort排序 my_list = [3 ...

  4. 牛客网 牛可乐发红包脱单ACM赛 C题 区区区间间间

    [题解] 我想到了两种解法. 一种是扫描线+线段树+单调栈. 另一种方法是O(n)的,比较巧妙. 考虑每个数在哪些区间可以作为最小数.最长的区间就是它向左右走,直到有数字比它小,这个可以用单调栈维护. ...

  5. PAT 1010. 一元多项式求导

    1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数 ...

  6. luogu4168 [Violet]蒲公英

    #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> ...

  7. selenium grid使用(windows+centos7.4)

    windows作为hub,centos7.4作为node. firefox用的centos7自带的52版本,懒得更新. vm虚拟机必须设置成bridge模式上网,否则报错.具体参见博文:Vmware改 ...

  8. POJ2421 Constructing Roads

    Constructing Roads 这道题很水,就是一个裸的最小生成树,最不过把已经连接的节点的值再设为0. 代码: #include<cstdio> #include<cstri ...

  9. HDU 1102 Kruscal算法

    题目大意:给定村庄的数量,和一个矩阵表示每个村庄到对应村庄的距离,矩阵主对角线上均为1 在给定一个数目Q,输入Q行之间已经有通道的a,b 计算还要至少修建多少长度的轨道 这道题目用Kruscal方法进 ...

  10. [POJ3041] Asteroids(最小点覆盖-匈牙利算法)

    传送门 题意: 给一个N*N的矩阵,有些格子有障碍,要求我们消除这些障碍,问每次消除一行或一列的障碍,最少要几次.   解析: 把每一行与每一列当做二分图两边的点. 某格子有障碍,则对应行与列连边. ...