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, ...
随机推荐
- JS添加DOM元素CSS权重BUG
修改删除table的时候,比如拆分合并单元格,合并全部TR中的某个TD后在拆分还原,即使直接在td标签中设置了td的高宽属性,当td在css文件中设置为宽度auto的时候,不能显示出TD来,显示TD宽 ...
- 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 从网上找到的解决方法,以此博客 ...
- win7下给右键菜单添加启动cmd命令
win7下给右键菜单添加启动cmd命令 (2013-07-20 19:20:56) 转载▼ 标签: it 右键 cmd 分类: 小软件操作技巧 最近编辑器在用windows下的gvim,但进入 ...
- express:webpack dev-server开发中如何调用后端服务器的接口?
开发环境: 前端:webpack + vue + vue-resource,基于如下模板创建的开发环境: https://github.com/vuejs-templates/webpack ...
- [MetaHook] Surface hook
Hook ISurface function. #include <metahook.h> #include <vgui/ISurface.h> using namespace ...
- lecture16-联合模型、分层坐标系、超参数优化及本课未来的探讨
这是HInton的第16课,也是最后一课. 一.学习一个图像和标题的联合模型 在这部分,会介绍一些最近的在学习标题和描述图片的特征向量的联合模型上面的工作.在之前的lecture中,介绍了如何从图像中 ...
- bash中变量+=,if大小判断,随机休眠
#!/bin/bash index= while true;do echo "hello" (( index+=)) echo `date "+%H:%M:%S" ...
- word-wrap,word-break和white-space总结
最近网页布局中遇到得比较多,所以打算总结总结. word-wrap: 1.normal(使用浏览器默认的换行规则) 2.break-word(内容将在边界内换行,但是英文换行会按词断句) word-b ...
- Windows Server+AMD GPU+HDMI时_黑边_不铺满问题的解决办法
HDMI接显示器或电视,有黑边或者被放大了是个很常见的问题,显卡设置界面里改下Scale或者Overscan/Underscan就行,可问题是WindowsServer版的CCC没有控制颜色对比度和缩 ...
- 3n+1b 备忘录方法
题目详情 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数学家大会上公布了这个猜 ...