POJ 1840:Eqs 哈希求解五元方程
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 14169 | Accepted: 6972 |
Description
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
Output
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 哈希求解五元方程的更多相关文章
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- POJ 1840 Eqs(hash)
题意 输入a1,a2,a3,a4,a5 求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立 a,x取值在-50到50之间 直接暴力的话肯定会超时的 100的五次方 10e了都 ...
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 Description ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Eqs 暴力
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...
- POJ 1840 Eqs(乱搞)题解
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...
- POJ 1681---Painter's Problem(高斯消元)
POJ 1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small s ...
随机推荐
- CentOS7 部署 Jupyter Notebook
socket.error: [Errno 99] Cannot assign requested address 修改这几处: 1.hostname 参考:https://www.cnblogs.co ...
- 2-10 就业课(2.0)-oozie:8、定时任务的执行
4.5.oozie的任务调度,定时任务执行 在oozie当中,主要是通过Coordinator 来实现任务的定时调度,与我们的workflow类似的,Coordinator 这个模块也是主要通过xml ...
- BVS安全检测之检查Linux是否口令生存周期
口令生存周期的配置文件为 /etc/login.defs vim 打开该文件,命令模式下输入 /PASS_MAX_DAYS 找到该配置信息的位置 我的Linux操作系统默认显示的是99999,说明我当 ...
- 一步步教你整合SSM框架(Spring MVC+Spring+MyBatis)详细教程重要
前言 SSM(Spring+SpringMVC+Mybatis)是目前较为主流的企业级架构方案,不知道大家有没有留意,在我们看招聘信息的时候,经常会看到这一点,需要具备SSH框架的技能:而且在大部分教 ...
- Windows上设置Sass
现在有很多信息在预处理器上浮动.大部分信息都面向Mac用户,所以在这篇文章中,我提供了一个非常简单的指南,帮助基于Windows的开发人员快速启动并运行Sass(我选择的预处理器). 本文是在此博客上 ...
- GoJS实例3
复制如下内容保存到空白的.html文件中,用浏览器打开即可查看效果 <!DOCTYPE html> <html> <head> <meta charset=& ...
- Python入门必学知识,30万年薪Python工程师带你学
Python是一种计算机编程语言.计算机编程语言和我们日常使用的自然语言有所不同,最大的区别就是,自然语言在不同的语境下有不同的理解,而计算机要根据编程语言执行任务,就必须保证编程语言写出的程序决不能 ...
- Verilog 2001 `default_nettype none
在Verilog 1995規定,對於沒宣告的信號會自動視為wire,這樣常常造成debug的困難,Verilog 2001另外定義了`default_nettype none,將不再自動產生wire. ...
- 用python实现在手机查看小姐姐的电脑在作什么!
看上心意的小姐姐,想看她平时都浏览什么网页,如何才能看她的桌面呢,都说Python很厉害,这次我们做一个利用移动端访问电脑来查看电脑的界面的神器!不知道大家以前有没有做过这方面的东西呢?也许大家听起来 ...
- 013.Oracle数据库,SUBSTR取子字符串
/*Oracle数据库查询日期在两者之间*/ SELECT EXPIRE_DATE , SUBSTR(EXPIRE_DATE , , ) FROM ME_EO WHERE ( ISSUE_DATE B ...