Eqs
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 14169   Accepted: 6972

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

给定方程是a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,给了a1,a2,a3,a4,a5。求解 解的数量。x都在-50到50之间。

暴搜肯定GG,就得把方程变形将a1x13+ a2x23
 
移到方程左边,作为结果,然后暴搜x3,x4,x5。时间复杂度就降下来了。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; short hash1[25000000]; int main()
{
int a1, a2, a3, a4, a5;
int x1, x2, x3, x4, x5;
int temp;
long long sum; scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5); memset(hash1, 0, sizeof(hash1));
for (x1 = -50; x1 <= 50; x1++)
{
if (x1 == 0)continue;
for (x2 = -50; x2 <= 50; x2++)
{
if (x2 == 0)continue; temp = -1*(a1*x1*x1*x1 + a2*x2*x2*x2); if (temp < 0)
{
temp += 25000000;
}
hash1[temp]++;
}
}
sum = 0;
for (x3 = -50; x3 <= 50; x3++)
{
if (x3 == 0)continue;
for (x4 = -50; x4 <= 50; x4++)
{
if (x4 == 0)continue;
for (x5 = -50; x5 <= 50; x5++)
{
if (x5 == 0)continue; temp = a3*x3*x3*x3 + a4*x4*x4*x4 + a5*x5*x5*x5; if (temp < 0)
{
temp += 25000000;
}
if (temp >= 0 && temp < 25000000)
{
sum += hash1[temp];
}
}
}
}
cout << sum << endl;
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1840:Eqs 哈希求解五元方程的更多相关文章

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

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

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

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

  3. poj 1840 Eqs (hash)

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

  4. POJ 1840 Eqs(hash)

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

  5. POJ 1840 Eqs

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

  6. POJ 1840 Eqs 二分+map/hash

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

  7. POJ 1840 Eqs 暴力

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

  8. POJ 1840 Eqs(乱搞)题解

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

  9. POJ 1681---Painter's Problem(高斯消元)

    POJ   1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small s ...

随机推荐

  1. Centos7关闭防火墙 设置开机启动

    [root@nmserver-7 ~]# systemctl stop firewalld.service [root@nmserver-7 ~]# systemctl status firewall ...

  2. lucene实践 - 索引维护、多域查询、高亮显示

    之前的博客搜索栏用的是 sql 模糊查询进行查找,最近学完lucene,要学以致用啊,就把sql搜索给替换下来吧 中间遇到一些问题,也是学过程中没有提到的,所以说,还是实践出真知啊. lucene分开 ...

  3. Java小项目之:教你做个聊天系统!

    Java小项目之:聊天系统 今天给大家带来的java练手小项目是一个简单的聊天室,界面简单,操作不难. 分为注册系统,登录系统和聊天系统三部分,很适合java小白练手. 完整的源码和素材请关注并私信我 ...

  4. Flask—核心对象app初步理解

    前言 flask的核心对象是Flask,它定义了flask框架对于http请求的整个处理逻辑.随着服务器被启动,app被创建并初始化,那么具体的过程是这样的呢? flask的核心程序就两个: 1.we ...

  5. json字符串转java对象,json中字段名称与对象属性名称不一致

    json字符串转java对象,json字段名称与对象属性名称不一致可以在对象属性上添加注解@SerializedName解决

  6. [题解] LuoguP2257 YY的GCD

    传送门 给\(n,m\),让你求 \[ \sum\limits_{i=1}^n \sum\limits_{j=1}^m [\gcd(i,j) \in prime] \] 有\(T\)组询问\((T \ ...

  7. MyBatis: No MyBatis mapper was found in '[xx.mapper]' package. Please check your configuration

    在应用入口加入@MapperScan("com.IBM.XXXXX.dao")

  8. 入门QT5 D1 Widget的移动

    又重温了一遍C++之后来看QT教程了.QT之前也看过,不过都是很长时间之前了,一直也用到. 反过来再一学,这是和学新的是一样一样的. 首先创建新项目. 1.点击NEW PROJECT 2.Applit ...

  9. HihoCoder第十四周:无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息--额,说远了,总之,小Hi和小H ...

  10. 无法执行 BACKUP LOG,因为当前没有数据库备份,导入数据库备份.bak文件

    右键数据库——>任务——>还原——>数据库 无法执行 BACKUP LOG,因为当前没有数据库备份 结尾日志的问题 还原选择中去掉结尾日志就可以了