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. OS、浏览器排名:Win10狂飙、Chrome逆天

    根据 Netmarketshare公布的最新数据,2019年7月,Windows 10系统市场份额获得显著增长,市场份额创下新高:Windows 7则进一步衰退,份额下滑高达3.6%,这也是其历史上最 ...

  2. 011.Delphi插件之QPlugins,延时加载服务

    这个DEMO是是把DLL插件的相关信息做成了一个配置文件,主程序加载这个配置文件,从而起到延时加载的作用 主程序代码如下 unit Frm_Main; interface uses Winapi.Wi ...

  3. mysql实现ORACLE的connect by prior父子递归查询

    oracle中有connect by prior ,可以实现父子递归查询.而mysql中没有这种功能,但我们可以变通实现. 比如一个表: Table Name: tb_Tree Id | Parent ...

  4. ActiveMQ的安装与配置详情

    (1)ActiveMQ的简介 MQ: (message queue) ,消息队列,也就是用来处理消息的,(处理JMS的).主要用于大型企业内部或与企业之间的传递数据信息. ActiveMQ 是Apac ...

  5. 04 MySQL数据类型

    MySQL支持的数据类型   1.数值类型:       a.整数类型    TINYINT 1字节 有符号(-128~127); 无符号(0~255) SMALLINT 2字节  有符号(-3276 ...

  6. NO8 find结合sed查找替换企业案例多方法精讲&命令总结!

    ·sed    #替换  eg: sed 'sed 's#已有的内容#更改的内容#g' oldboy.txt                   s 代表替换,g代表全局,sg就是全局替换       ...

  7. Day 24:XML基础

    Q: 什么是XML,为什么学习XML? A:XML为可扩展标记语言. 标签由开发者自己制定的(要按照一定的语法定义)描述带关系的数据(作为软件的配置文件): 包含与被包含的关系 properties文 ...

  8. Metasploitable学习(一)

    划红线的是执行语句,对已知的服务器的IP地址进行扫描.嗅探

  9. python面试题整理(二)

    1.进程,线程,协程定义,有什么区别 进程是操作系统分配资源的最小单位,一个进程对应一块CPU 线程是进程中的某一个控制单元,是CPU调度的最小单元,线程之间相互独立,进程结束线程也会结束,一个进程至 ...

  10. OpenJudge - NOI - 1.1编程基础之输入输出(C语言 全部题解)

    01:Hello, World! #include <stdio.h> int main(void) { printf("Hello, World!"); return ...