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. tabs标签页的数据缓存

    一进入tabs标签页默认就将所有标签页的数据请求到,并渲染到页面上, 这样如果数据量太大的话会渲染很久, 我的需求就是点击不同的标签时再请求数据,同时对点击过的标签页数据进行缓存,下次点击时不再重新请 ...

  2. POJ-1002-487-3279(字符串)

    487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 309685 Accepted: 55292 Descripti ...

  3. (5) openssl speed(测试算法性能)和openssl rand(生成随机数)

    1.1 openssl speed 测试加密算法的性能 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-cb ...

  4. hihoCoder#1133 二分·二分查找之k小数

    原题地址 经典问题了,O(n)时间内找第k大的数 代码: #include <iostream> using namespace std; int N, K; int *a; int se ...

  5. 数字游戏(codevs 1085)

    题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共 ...

  6. [NOIP2002] 提高组P1032 字串变换

    题目描述 已知有两个字串 A, B 及一组字串变换的规则(至多6个规则): A1 -> B1 A2 -> B2 规则的含义为:在 A$中的子串 A1 可以变换为 B1.A2 可以变换为 B ...

  7. [Usaco2007 Oct] Super Paintball超级弹珠

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 489  Solved: 384[Submit][Status][Discuss] Description ...

  8. 深入理解计算机操作系统——第11章:全球IP英特网

    全球IP英特网 (1)每台英特网主机都运行实现TCPIP协议的软件. (2)英特网的客户端和服务器混合使用套接字接口函数和Unix IO函数来进行通信. (3)套接字函数典型的是作为陷入内核的系统调用 ...

  9. 希尔排序(shell)

    希尔排序: 思路: 希尔排序是插入排序的一种改进的版本. 先将整个待排序记录序列分割成若干个子序列,在在序列内分别进行直接插入排序,待整个序列基本有序时,再对全体记录进行一次直接插入排序. 这里增量序 ...

  10. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...