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. SQL Server 2008 阻止保存要求重新创建表的更改

    取消[阻止保存要求重新创建表的更改]复选框

  2. focus,focusin,blur,focusout区别

    focus与focusin 1.共同点:当 <div> 元素或其任意子元素获得焦点时执行事件 2.区别:focus不支持冒泡,而focusin支持冒泡: blur与focusout 1.共 ...

  3. mysql踩坑

    com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value '****** ...

  4. 21. SCHEMATA

    21. SCHEMATA 在MySQL中,SCHEMA是数据库,因此SCHEMATA表提供有关数据库的信息. SCHEMATA表有以下列: CATALOG_NAME :SCHEMA所属目录的名称.该值 ...

  5. root连接ubuntu18.04“拒绝访问”的解决方法

    1.设置root账户 sudo passwd root 2.ssh远程登陆拒绝访问:修改SSH配置文件 sudo vim /etc/ssh/sshd_config 找到并用#注释掉这行:PermitR ...

  6. Python能干啥?

    Python之py9 Python之py9-录音自动下载 Python之py9-py9作业检查 Python之py9-py9博客情况获取 Python之py9-微信监控获取mp3_url Python ...

  7. LeetCode(26) Remove Duplicates from Sorted Array

    题目 Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  8. Hibernate入门(1)——环境搭建

    什么是Hibernate?为什么使用Hibernate?Hibernate有什么优缺点?网上很多大神的文章又详细又通俗易懂. 步骤: 1.创建数据库表格. 2.编写JavaBean实体类. 3.下载H ...

  9. 【Codeforces 140A】New Year Table

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 算出来每个盘子要占用多少角度. 然后乘n看看是不是小于等于2π就好 (精度最好定在1e-7) [代码] #include <bits/s ...

  10. 使用JQuery.slideBox实现图片滚动效果

    1.下载JQuery.slideBox和jquery插件,并引用 <link href="css/jquery.slideBox.css" rel="stylesh ...