POJ 1840 Eqs
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 15010 | Accepted: 7366 |
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
Source
按要求模拟即可
hash是个神奇的东西
下方代码注释部分是先三层循环后二层,正文部分是先二层循环后三层。两者都是正解,但是由于list插入比读取慢,先二层更快
/*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
const int mxn=14997;
list<int>ha[mxn*2];
list<int>::iterator it;
int x,x1,x2,x3,x4,x5;
int ans=0;
int main(){
scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
int i,j,k;
for(i=-50;i<=50;i++)
for(j=-50;j<=50;j++)
for(k=-50;k<=50;k++){
if(i==0||j==0||k==0)continue;
x=i*i*i*x1+j*j*j*x2+k*k*k*x3;
ha[x%mxn+mxn].push_back(x);//hash //x%mxn+mxn保证hash完以后是正数
}
for(i=-50;i<=50;i++)
for(j=-50;j<=50;j++){
if(i==0|j==0)continue;
x=-(i*i*i*x4+j*j*j*x5);
//检查hash
for(it=ha[x%mxn+mxn].begin();it!=ha[x%mxn+mxn].end();it++ ){
if(*it==x)ans++;
}
}
printf("%d",ans);
return 0; }
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
const int mxn=;
list<int>ha[mxn*];
list<int>::iterator it;
int x,x1,x2,x3,x4,x5;
int ans=;
int main(){
scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
int i,j,k;
for(i=-;i<=;i++)
for(j=-;j<=;j++)
{
if(i==||j==)continue;
x=i*i*i*x1+j*j*j*x2;
ha[x%mxn+mxn].push_back(x);//hash //x%mxn+mxn保证hash完以后是正数
}
for(i=-;i<=;i++)
for(j=-;j<=;j++)
for(k=-;k<=;k++){
if(i==|j==||k==)continue;
x=-(i*i*i*x3+j*j*j*x4+k*k*k*x5);
//检查hash
for(it=ha[x%mxn+mxn].begin();it!=ha[x%mxn+mxn].end();it++ ){
if(*it==x)ans++;
}
}
printf("%d",ans);
return ; }
niconiconi
POJ 1840 Eqs的更多相关文章
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- 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 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- POJ 1840 Eqs(hash)
题意 输入a1,a2,a3,a4,a5 求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立 a,x取值在-50到50之间 直接暴力的话肯定会超时的 100的五次方 10e了都 ...
- 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 1840:Eqs 哈希求解五元方程
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14169 Accepted: 6972 Description ...
- Eqs - poj 1840(hash)
题意:对于方程:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,有xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 现在给出a1,a2,a3, ...
随机推荐
- Windows 8.1 新增控件之 DatePicker
大年初一来介绍一个简单易用的DatePicker 控件,这个控件是新增的?印象里很早就有了啊,Anyway来看看Windows 8.1 里的DataPicker 有什么功能吧. 先来看看这个代码,很简 ...
- (转)c# 解析JSON的几种办法
来自:http://blog.csdn.net/gaofang2009/article/details/6073029 欲成为海洋大师,必知晓海中每一滴水的真名. 刚开始只是想找一个转换JSON数组的 ...
- windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes 解决方案
win7 MySql5.6.17提示:1045 access denied for user 'root'@'localhost' using password yes 从网上找到的解决方法,以此博客 ...
- 写Java也得了解CPU--CPU缓存
CPU,一般认为写C/C++的才需要了解,写高级语言的(Java/C#/pathon...)并不需要了解那么底层的东西.我一开始也是这么想的,但直到碰到LMAX的Disruptor,以及马丁的博文,才 ...
- opencv7-ml之svm
因为<opencv_tutorial>这部分只有两个例子,就先暂时介绍两个例子好了,在refman中ml板块有:统计模型.普通的贝叶斯分类器.KNN.SVM.决策树.boosting.随机 ...
- 发布新款博客皮肤SimpleMemory
感谢 sevennight 又为大家精心设计了一款简约风格的博客皮肤 —— SimpleMemory. 大家可以通过这篇博文感受一下实际的效果:开园子啦(浅谈移动端以及h5的发展) 如果您喜欢这款皮肤 ...
- SQLite常用点滴总结(转)
expressionexpr ::= expr binary-op expr |expr [NOT] like-op expr [ESCAPE expr] |unary-op expr |( ...
- nios II--实验2——led软件部分
软件开发 首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分:打开toolsàNios II 11.0 Software Build Tools for Eclipse,需要进 ...
- leetcode-Warm Up Contest-Aug.21
leetcode 地址: https://leetcode.com/contest/detail/1 (1)-- Lexicographical Numbers Given an integer ...
- Tomcat本地服务器搭建
首先,下载jdk-8u111-windows-x64.exe,然后配置环境,以安装目录D:\jdk1.8.0_111为例: 新建一个变量: 然后打开path新建两个变量: 最后去控制台敲javac或者 ...