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. word里的代码格式,使之有底纹的效果

      实现效果: 怎么才能在word里实现这样的显示? 如何设置word里的代码格式,使之有底纹的效果

  2. linux不同角色server分区方案

    服务器角色 分区建议 优点    RAID方案 单机服务器 如8G内存,300G硬盘        /boot 100-200M swap 16G,内存大小8G*2 / 80G /var 20G(也可 ...

  3. java:POI导出excel

    POI是一个开源项目,专用于java平台上操作MS OFFICE,企业应用开发中可用它方便导出Excel. 下面是使用示例: 1.maven中先添加依赖项 <dependency> < ...

  4. React Native 中组件的生命周期

    概述 就像 Android 开发中的 View 一样,React Native(RN) 中的组件也有生命周期(Lifecycle).所谓生命周期,就是一个对象从开始生成到最后消亡所经历的状态,理解生命 ...

  5. [转]Android中Xposed框架篇—利用Xposed框架实现拦截系统方法

    一.前言 关于Xposed框架相信大家应该不陌生了,他是Android中Hook技术的一个著名的框架,还有一个框架是CydiaSubstrate,但是这个框架是收费的,而且个人觉得不怎么好用,而Xpo ...

  6. PHP 实现页面静态化

    PHP文件执行阶段:语法分析->编译->运行 静态html文件执行顺序:运行 动态程序: 连接数据库服务器或者缓存服务器->获取数据->填充到模板->呈现给用户 关于优化 ...

  7. 【JavaEE企业应用实战学习记录】struts国际化

    <%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To change this tem ...

  8. java 数据绑定的几种方式及相关注意事项-持续更新

    spring mvc 中会遇到各种数据绑定,有些不常用的,但是千万不要觉得不可以,没有什么是不可以的,只要能够想到,就可以. 数据绑定方式: 1. 注意: 当数据为包装类型的数字型时,如果Long h ...

  9. ViewPager导航栏TabLayout

    ViewPager中加入TabLayout导航 需要导入依赖包:  'com.android.support:appcompat-v7:xxxxx' compile 'com.android.supp ...

  10. 高手详解SQL性能优化十条经验

    1.查询的模糊匹配 尽量避免在一个复杂查询里面使用 LIKE '%parm1%'—— 红色标识位置的百分号会导致相关列的索引无法使用,最好不要用. 解决办法: 其实只需要对该脚本略做改进,查询速度便会 ...