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. strcpy vs memcpy

    [本文连接] http://www.cnblogs.com/hellogiser/p/strcpy_vs_memcpy.html [分析] strcpy和memcpy都是标准C库函数,它们有下面的特点 ...

  2. java web 学习 --第八天(Java三级考试)

    第七天的学习内容:http://www.cnblogs.com/tobecrazy/p/3464231.html EL表达式 EL : Expression Language 使用EL表达式可以减少& ...

  3. MySQL(MariaDB)的 SSL 加密复制

    背景: 在默认的主从复制过程或远程连接到MySQL/MariaDB所有的链接通信中的数据都是明文的,在局域网内连接倒问题不大:要是在外网里访问数据或则复制,则安全隐患会被放大很多.由于项目要求需要直接 ...

  4. TokuDB 引擎安装测试

    背景: TokuDB引擎是有Tokutek开发的一个数据库存储引擎,在设计之初便引入了独特的索引算法,在其官网测试的文章中看到TokuDB性能比InnoDB高出很多. MySQL是一个插件式的数据库, ...

  5. nyoj305_表达式求值

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...

  6. DP:Cow Exhibition(POJ 2184)(二维问题转01背包)

        牛的展览会 题目大意:Bessie要选一些牛参加展览,这些牛有两个属性,funness和smartness,现在要你求出怎么选,可以使所有牛的smartness和funness的最大,并且这两 ...

  7. codeforces 495C. Treasure 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...

  8. IOS - 响应者链条

    简单来说就是:一级一级的找到响应的视图,如果没有就传给UIWindow实例和UIApplication实例,要是他们也处理不了,就丢弃这次事件... 对于IOS设备用户来说,他们操作设备的方式主要有三 ...

  9. [Ubuntu] ubuntu10.04系统维护之Wine的安装

    在介绍安装wine之前,我想是有必要先介绍一下Wine的.当然,如果是Liunx的高手,我想是没必要看的,但是对于笔者这样的菜鸟级人物还是需要看一下的. Wine是一款Liunx下的模拟器软件,但是W ...

  10. August 15th 2016 Week 34th Monday

    Why not discovering as there is glorious faraway scenery? 远方有诗篇,何不去发现? An advertisement of Land Rove ...