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. Android Studio中出现Gradle's dependency cache may be corrupt错误的解决办法

    起因 某次打开AS,提示升级AS,升级后,提示升级gradle,选择升级. 结果在升级gradle时耗时较久,没有耐心,点击停止升级gradle, 还是停在那里,然后关闭AS,还是没反应,启动任务管理 ...

  2. 6. 将单独表空间(File-Per-Table Tablespaces)复制到另一个实例

    6. 将单独表空间复制到另一个实例 本节介绍如何将单独表空间从一个MySQL实例复制 到另一个MySQL实例,也称为可传输表空间功能. 将InnoDB单独表空间复制到其他实例的原因有很多: - 在不对 ...

  3. Python数据可视化库-Matplotlib(二)

    我们接着上次的继续讲解,先讲一个概念,叫子图的概念. 我们先看一下这段代码 import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.a ...

  4. pycharm的快捷键以及常用设置

    1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + Shift + Enter 语句完成 Ctr ...

  5. 杭电 1213 How Many Tables (并查集求团体数)

    Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius ...

  6. luogu3959 宝藏

    状压搜索轻轻松松就过了--考场上代码太丑了T了几个点 #include <iostream> #include <cstring> #include <cstdio> ...

  7. prototype 和function关系等总结

    js提供了一些内置类,如Array String Function等,只要有类就有原型. 1,function ,属性包括 arguments, caller,length,name ,prototy ...

  8. Javascript拼接HTML字符串的方法列举及思路

    转载过来,去掉一些废话吧. 目标: 方便的拼接字符串,不使用让人眼晕的+=.使用过程如下: 1,先创建一个作为“模板”的字符串,如:’My name is ${name},I\’m ${age}.’ ...

  9. Spring使用JdbcTemplate实现对数据库操作

    https://www.cnblogs.com/tuhooo/p/6491913.html https://blog.csdn.net/maodoubi/article/details/4826723 ...

  10. 矩形周长(codevs 2149)

    题目描述 Description N(N<5000) 张矩形的海报,照片和其他同样形状的图片贴在墙上.它们的边都是垂直的或水平的.每个矩形可以部分或者全部覆盖其他矩形.所有的矩形组成的集合的轮廓 ...