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 ...
随机推荐
- android侧滑效果(引用官方网站提供的API文件)
原文地址:http://www.cnblogs.com/android100/p/android-SlidingMenu.html 在新浪微博和唱吧里面都有看到android的侧滑效果,于是想要学习一 ...
- UVA - 816 Abbott's Revenge(bfs)
题意:迷宫从起点走到终点,进入某点的朝向不同,可以出去的方向也不同,输出最短路. 分析:因为朝向决定接下来在该点可以往哪里走,所以每个点需要有三个信息:x,y,d(坐标和进入该点的朝向),所以将起点的 ...
- flask邮箱注册问题
app/models.py self.confirmed = True db.session.add(self) db.session.commit() 这里的数据修改完后必须commit提交上去,不 ...
- ES6与ES5的继承
ES6 ES6中的类 类与ES5中的构造函数写法类似 区别在于属性要放入constructor中,静态方法和属性实列不会继承 <script> class Person{ height=& ...
- Zookeeper 在 Kafka 中的作用
https://www.jianshu.com/p/a036405f989c 待整理...
- 了解C#
了解C C#能编写那些程序 Windows桌面应用程序 桌面应用有自己独立的进程与操作系统进行消息通讯,操作系统对事件进行检测,传递给桌面应用进程,桌面应用进程对这些消息进行解释,处理后,把处理结果u ...
- 控制数据的小数位数 java / js
//java一般控制格式都是通过 DecimalFormat 来控制的.下边是个例子. import java.text.DecimalFormat; public class ControlBit ...
- 实验吧-隐写术-男神一般都很低调很低调的!!(stegsolve->Image Combiner + DES加密)
先介绍一下DES加密:(也可参考https://blog.csdn.net/zz_Caleb/article/details/87016017,第14个) 1)对称加密,参考:对称加密和非对称加密 2 ...
- ACM-数细胞
题目描述:数细胞 一矩形阵列由数字0到9组成,数字1到9代表细胞,细胞的定义为沿细胞数字上下左右还是细胞数字则为同一细胞,求给定矩形阵列的细胞个数.编程需要用到的队列及其相关函数已经实现,你只需要完成 ...
- MongoDB七-运维技术
复制来自:http://www.cnblogs.com/huangxincheng/archive/2012/03/08/2384571.html 这一篇我们以管理员的视角来看mongodb,作为一名 ...