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. struts2 校验demo

    综合练习: <validators> <field name="username"> <field-validator type="requ ...

  2. fork详解

    [本文链接] http://www.cnblogs.com/hellogiser/p/fork.html [代码] 下面的代码输出多少个-?  C++ Code  123456789101112131 ...

  3. 迷宫问题_BFS_挑战程序设计竞赛p34

    给定一个N*M的迷宫,求从起点到终点的最小步数. N,M<100: 输入: 10 10#S######.#......#..#.#.##.##.#.#........##.##.####.... ...

  4. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

  5. 将jquery和公共样式缓存到localStorage,可以减少Http请求,从而优化页面加载时间

    以下代码: //入口函数 if (window.localStorage) { initJs(); initCss("css", "/gfdzp201508257998/ ...

  6. code vs1262 不要把球传我(组合数学) 2012年CCC加拿大高中生信息学奥赛

    1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 De ...

  7. webclient 和httpclient 应用

    //webclient应用 MyImageServerEntities db = new MyImageServerEntities(); public ActionResult Index() { ...

  8. android中判断网络连接是否可用

    一.判断网络连接是否可用 public static boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (C ...

  9. Crystal Report 遇到需要登录的问题

    解决方式: The advices for crystal report database connection settings: 1, Using ApplyLogOnInfo method in ...

  10. SQL Server output经典使用

    output经典使用 分类: sql2012-02-16 18:17 409人阅读 评论(0) 收藏 举报 outputinserttabledeletegonull OUTPUT是SQL SERVE ...