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 ...
随机推荐
- vue table已选列数据
vue Table@on-selection-change="test" 已选中项数据 test(selection){} <Table :data="tableD ...
- Day8 - F - Tree POJ - 1741
Give a tree with n vertices,each edge has a length(positive integer less than 1001).Define dist(u,v) ...
- Educational Codeforces Round 65 选做
好久没更博客了,随便水一篇 E. Range Deleting 题意 给你一个长度为 \(n\) 的序列 \(a_1,a_2,\dots a_n\) ,定义 \(f(l,r)\) 为删除 \(l\le ...
- getchar、scanf以及缓冲区的概念
1.getchar()是stdio.h中的库函数,它的作用是从stdin流中读入一个字符,也就是说,如果stdin有数据的话不用输入它就可以直接读取了. getch()和getche( ...
- NO12 useradd-passwd-uname-hostname命令-上传rz下载sz-批量部署- Linux用户相关操作
24 useradd #添加用户 语法:useradd 用户名 例子:ueradd oldboy .25 passwd #为用户设置或修改 ...
- SQL注入汇总(手注,盲注,报错注入,宽字节,二次编码,http头部){10.22、23 第二十四 二十五天}
首先什么是SQL注入: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. SQL注入有什么危害? 危害:数据泄露.脱库 ...
- 【pwnable.kr】lotto
pwnable.好像最近的几道题都不需要看汇编. ssh lotto@pwnable.kr -p2222 (pw:guest) 直接down下来源码 #include <stdio.h> ...
- git仓库拆分
例如: # 这就是那个大仓库 big-project $ git clone git@github.com:tom/big-project.git $ cd big-project # 把所有 `co ...
- 指令——less
一.Liunx系统下的一般命令格式. 命令——实际上就是在Liunx终端中,在命令行中输入的内容. Liunx中一个命令的完整格式为: #指令主体(空格) [选项](空格) [操作对象] 指令主体—— ...
- 151-PHP nl2br函数(二)
<?php $str="h\nt\nm\nl"; //定义一个多处换行的字串 echo "未处理前的输出形式:<br />{$str}"; $ ...