Eqs
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 15010   Accepted: 7366

Description

Consider equations having the following form: 
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

The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.

Output

The output will contain on the first line the number of the solutions for the given equation.

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的更多相关文章

  1. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

  2. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  3. poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 6851 Description ...

  4. POJ 1840 Eqs(hash)

    题意  输入a1,a2,a3,a4,a5  求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立   a,x取值在-50到50之间 直接暴力的话肯定会超时的   100的五次方  10e了都 ...

  5. POJ 1840 Eqs 二分+map/hash

    Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...

  6. POJ 1840 Eqs 暴力

      Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...

  7. POJ 1840 Eqs(乱搞)题解

    思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...

  8. POJ 1840:Eqs 哈希求解五元方程

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14169   Accepted: 6972 Description ...

  9. 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, ...

随机推荐

  1. Castle.ActiveRecord 多对多关系 引发的错误处理

    在Castle.ActiveRecord 实体类中,如果两个对象有 “多对多” 关系,一般的做法是将其分解为 两个“一对多”关系,但有时引发了 “您要删除 或 引用 的对象#2在数据库中不存在”的异常 ...

  2. Easyui Tree方法扩展 - getLevel(获取节点级别)

    Easyui Tree一直就没有提供这个方法,以前没有用到,所以一直没怎么在意,这次自己用到了,顺便扩展了一个方法,分享给大家. $.extend($.fn.tree.methods, { getLe ...

  3. [转]Gson过滤字段

    原文地址:http://my.oschina.net/orgsky/blog/368768 摘要 Gson过滤字段 Gson过滤字段 Gson 过滤 字段 属性 目录[-] 最简单的用法 方法1:排除 ...

  4. web—第四章css&第五章

     web—第四章css&第五章 终于迎接等待已久的CSS,在没学这个之前,我们只会用一点img,查一点小图片,或者是用style改一下颜色,而且比较麻烦.现在多了个css在文件夹在创建一个cs ...

  5. ssh 免密码设置失败原因总结

    先复习一下设置ssh免密码操作的步骤: 进入主目录 cd 生成公钥 ssh-keygen -t rsa -P '' (注:最后是二个单引号,表示不设置密码) 然后分发公钥到目标机器 ssh-copy- ...

  6. ffmpeg在shell循环中只执行一次问题

    最近写了一个shell脚本,发现 ffmpeg 命令只执行了一次就停了,最后找到原因: ffmpeg有时会读取标准输入流,导致命令出错,解决办法是在ffmpeg命令之后添加 #xxx ffmpeg x ...

  7. 让计算机崩溃的python代码,求共同分析

    在现在的异常机制处理的比较完善的编码系统里面,让计算机完全崩溃无法操作的代码还是不多的.今天就无意运行到这段python代码,运行完,计算机直接崩溃,任务管理器都无法调用,任何键都用不了,只能强行电源 ...

  8. java发送邮件

    1.需要用到javax.mail怎么下载呢?百度javax.mail就会看见http://www.oracle.com/technetwork/java/index-138643.html实际上这个项 ...

  9. 【JavaEE企业应用实战学习记录】struts配置文件详细解析

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  10. Spring + SpringMVC + MyBatis

    1.需求说明实现用户通过数据库验证登录需求,采用Myeclipse+Tomcat 6.0+Mysql 5.0+JDK 1.6 2.数据库表开发所用是Mysql数据库,只建立单张用户表T_USER,表结 ...