题意:对于方程:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,有xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 现在给出a1,a2,a3,a4,a5的值,求出满足上面方程的解有多少个。

思路:hash的应用。暴力枚举的话会达到100^5,明显会超时。所以将方程分成-(a1x13+ a2x23 )和 a3x33+a4x43+ a5x53 两部分,若这两部分相等,则为方程的一个解。

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
short hash[];
int main(){
int coff[],base[];
int i,j,k;
int result=;
for(i=;i<;i++){
scanf("%d",&coff[i]);
}
for(i=-;i<=;i++){
int tmp=i*i*i;
base[i+]=tmp;
}
memset(hash,,sizeof(hash));
for(i=-;i<=;i++){
for(j=-;j<=;j++){ if(i!=&&j!=){
int tmp=coff[]*base[i+]+coff[]*base[j+];
hash[tmp+]++;
}
}
} for(i=-;i<=;i++){
for( j=-;j<=;j++){
for(k=-;k<=;k++){
if(i!=&&j!=&&k!=){
int tmp=coff[]*base[i+]+coff[]*base[j+]+coff[]*base[k+];
tmp=-tmp;
if(tmp<&&tmp>=-)
result+=hash[tmp+];
} } }
}
printf("%d\n",result);
return ;
}

附:

Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 14021   Accepted: 6889

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

Eqs - poj 1840(hash)的更多相关文章

  1. POJ 1840 HASH

    题目链接:http://poj.org/problem?id=1840 题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1 ...

  2. poj 1840 Eqs (hash)

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

  3. POJ 1840 Eqs 二分+map/hash

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

  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

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

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

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

  7. POJ 1840 Eqs(乱搞)题解

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

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

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

  9. POJ 1840:Eqs

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

随机推荐

  1. win8.1 64位环境搭建android开发环境

    1.下载JDK,http://www.oracle.com/technetwork/java/javase/downloads/index.html,选择版本 2.安装刚刚下载的JDK 3.环境变量配 ...

  2. 《大规模web服务开发技术》笔记

    前段时间趁空把<大规模web服务开发技术>这本书看完了,今天用一下午时间重新翻了一遍,把其中的要点记了下来,权当复习和备忘.由于自己对数据压缩.全文检索等还算比较熟,所以笔记内容主要涉及前 ...

  3. 【笔记】探索js 的this 对象 (第一部分)

    最近在看 你不知道的javascript 这本书,在第二部分看到了一个比较重要的知识点 那就是 this对象的全面认识,于是做一下笔记 博主本人在看这本书之前也一直以为 this 是指一切引用类型的本 ...

  4. eclipse中使用mybatis-generator逆向代码生成工具问题解决记录

    问题一: eclipse中使用mybatis-generator逆向代码生成工具出现waiting for "building  workspace" 解决办法: 选择菜单栏的   ...

  5. 金蝶随手记团队分享:还在用JSON? Protobuf让数据传输更省更快(实战篇)

    本文作者:丁同舟,来自金蝶随手记技术团队. 1.前言 本文接上篇<金蝶随手记团队分享:还在用JSON? Protobuf让数据传输更省更快(原理篇)>,以iOS端的Objective-C代 ...

  6. 算法笔记_116:算法集训之代码填空题集三(Java)

     目录 1 数组转置 2 文件管理 3 显示为树形 4 杨辉三角系数 5 圆周率与级数 6 整数翻转 7 自行车行程 8 祖冲之割圆法 9 最大5个数 10 最大镜像子串   1 数组转置 编写程序将 ...

  7. c++11 Using Callable Objects, std::thread, std::bind, std::async, std::call_once

  8. 轻量级php框架phpk v1.0发布

    phpk框架简介 PHPK是一个简单易用,易于扩展的轻量级PHP框架.phpk不仅仅是一个php框架,也是一个js框架,内置一套全新的js内库,完全摒弃了庞大的jquery,所有的前端都是一个全新的微 ...

  9. 使用 WinEdt 来写中文文章or 建模论文

    找了几乎两个小时…… 后来发现… WinEdt 是可以用来写中文文章的…而并非只能英文文章或演示文稿… \documentclass{article} \usepackage{CJK} \begin{ ...

  10. sql server删除数据时如何进行级联删除

    可以在创建外键约束时直接设置级联删除