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

题意:
给出5个数(<=50)a1,a2,a3,a4,a5 ,分别与5个未知数的3次方 联立方程=0 为a1x1^3+ a2x2^3+a3x3^3+ a4x4^3+ a5x5^3=0  |xi|<=50并xi!=0 求有多少组解。
题解
二分+map标记,先暴力出x1,x2,x3对应的a1x13+ a2x23+ a3x33 ; 存入数组中,再对应暴力 去 二分查找出等于 负的a4*x43次方+a5*x53次方 相应的下标 及对应个数; 代码:
 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define MOD 1000000007
#define maxn 20000001
using namespace std;
typedef long long LL;
int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//*******************************************************************
__int64 a[];
map< int ,int > mp;
int t;
int jug(__int64 x)
{ int l=;
int r=t;
int xx;
int mid;
while(l<=r)
{
mid=(l+r)/;
if(a[mid]>x)
{
r=mid-;
}
else if(a[mid]<x)
{
l=mid+;
if(a[l]==x)return mp[x];
}
else return mp[x];
}
return ;
}
int main()
{ int a1,a2,a3,a4,a5;
t=;
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
for(int x1=-; x1<=; x1++)
{
if(x1==) continue;
for(int x2=-; x2<=; x2++)
{
if(x2==)continue;
a[++t]=(a1*x1*x1*x1+a2*x2*x2*x2);
if(mp.count(a[t]))
mp[a[t]]++;
else mp[a[t]]=;
}
}
sort(a+,a+t+);
int ans=;
for(int x3=-; x3<=; x3++)
{
if(x3==)continue;
for(int x4=-; x4<=; x4++)
{
if(x4==) continue;
for(int x5=-; x5<=; x5++)
{
if(x5==) continue;
__int64 aaa=-*(a3*x3*x3*x3+x4*a4*x4*x4+a5*x5*x5*x5);
ans+=jug(aaa);
}
}
}
printf("%d\n",ans);
return ;
}
  这是哈希标记法
 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define maxn 25000000
#define inf 1000000007
using namespace std;
typedef long long LL;
int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//********************************************************** short hash[];
int main()
{
int a1,a2,a3,a4,a5,x1,x2,x3,x4,x5,sum;
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
memset(hash,,sizeof(hash));
for(x1=-; x1<=; x1++)
{
if(x1==)
continue;
for(x2=-; x2<=; x2++)
{
if(x2==)
continue;
sum=(a1*x1*x1*x1+a2*x2*x2*x2)*-;
if(sum<)sum+=maxn;
hash[sum]++;
}
}
int cnt = ;
for(x3=-; x3<=; x3++)
{
if(x3==)
continue;
for(x4=-; x4<=; x4++)
{
if(x4==)
continue;
for(x5=-; x5<=; x5++)
{
if(x5==)
continue;
sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if(sum<)sum+=maxn;
cnt+=hash[sum];
}
}
}
printf("%d\n",cnt);
return ;
}
												

POJ 1840 Eqs 二分+map/hash的更多相关文章

  1. poj 1840 Eqs (hash)

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

  2. poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】

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

  3. POJ 1840 Eqs(hash)

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

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

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

  5. POJ 1840 Eqs

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

  6. POJ 1840 Eqs(乱搞)题解

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

  7. POJ 1840 Eqs 暴力

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

  8. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  9. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

随机推荐

  1. linux /usr/bin/ld cannot find 解决

    问题: 在linux环境编译应用程式或lib的source code时常常会出现如下的错误讯息: /usr/bin/ld: cannot find -lxxx 这些讯息会随着编译不同类型的source ...

  2. QListWidget

    1.失去焦点背景颜色,代码设置全选的时候,背景会是白色,需要设置失去焦点背景颜色.(设置焦点,会出现白转化成设置背景色,效果不好) QPalette p; p.setColor(QPalette::I ...

  3. MySQL中无GROUP BY直接HAVING的问题【转】

    本文来自网址: http://www.penglixun.com/tech/database/having_without_groupby_in_mysql.html 今天有同学给我反应,有一张表,i ...

  4. percona-toolkit 之 【pt-slave-delay】说明

    摘要: 在主从复制的架构中,正常情况下主上操作的记录也会在从上进行操作,虽说是异步复制,但操作会“实时”的同步到从.比如在主上不小心误操作了,还没等反应过来从上也会马上执行误操作,后期只有通过二进制或 ...

  5. Centos 用户登录失败N次后锁定用户禁止登陆

    针对linux上的用户,如果用户连续3次登录失败,就锁定该用户,几分钟后该用户再自动解锁 Linux有一个pam_tally2.so的PAM模块,来限定用户的登录失败次数,如果次数达到设置的阈值,则锁 ...

  6. 带中文的路径导致NSURL初始化一直为null的问题

    一.问题描述 在学习Ojective-C过程中,需要读取文件中的内容,但发现指针变量url的值一直为nil. 代码如下: NSString *strUrl=@"file:///Users/f ...

  7. 【python】类变量和对象变量

    来源:http://www.cnblogs.com/gtarcoder/p/5005897.html python是一种解释性的语言,任何变量可以在使用的时候才声明以及定义,也可以在程序运行的任何位置 ...

  8. 20145213《Java程序设计》第四周学习总结

    20145213<Java程序设计>第四周学习总结 教材学习内容总结 本周任务是学习面向对象的继承.接口以及之后的如何活用多态.(还真是路漫漫其修远兮啊!)教材也是延续上周艰深晦涩的语言风 ...

  9. mysql无法启动

    当在安装mysql服务时,有时会遇到恶心的PID错误而导致安装后无法启动以下为针对mysql-5.5版本在安装mysql时所遇到的问题的解决方法. 1.可能是/usr/local/mysql/data ...

  10. supersr--去除tableViewHeader的粘性

    这段代码能去除tableViewHeader的粘性 const static NSInteger kSectionHeaderHeight = 30; - (void)scrollViewDidScr ...