题意:对于方程: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. WPF使用ARCGIS App文件配置Cs后台文件

    using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...

  2. Python描写叙述符(descriptor)解密

    Python中包括了很多内建的语言特性,它们使得代码简洁且易于理解.这些特性包括列表/集合/字典推导式,属性(property).以及装饰器(decorator).对于大部分特性来说,这些" ...

  3. Some Web API Url Samples

    URI                               Verb     Description                                               ...

  4. php读取ini(init)文件

    <?php header('content-type:text/html;charset=utf-8'); //读取.init文件 $config_file_path = './config/d ...

  5. javascript对于0的解读

      CreateTime--2017年6月29日10:36:01Author:Marydon javascript对于0的解读 1.0与“0” 1.1 判断0与"0"是否相等 测试 ...

  6. javascript Date日期类

      四.Date日期类 迁移时间:2017年5月27日18:43:02 Author:Marydon (一)对日期进行格式化(日期转字符串) 自定义Date日期类的format()格式化方法 方式一: ...

  7. poj3177 Redundant Paths 边双连通分量

    给一个无向图,问至少加入多少条边能够使图变成双连通图(随意两点之间至少有两条不同的路(边不同)). 图中的双连通分量不用管,所以缩点之后建新的无向无环图. 这样,题目问题等效于,把新图中度数为1的点相 ...

  8. 网络请求框架---Volley

    去年的Google I/O大会为android开发者带来了一个网络请求框架,它的名字叫做Volley.Volley诞生的使命就是让Android的网络请求更快,更健壮,而且它的网络通信的实现是基于Ht ...

  9. bbc mvn报错

    http://www.cnblogs.com/zhouyalei/archive/2011/11/30/2268606.html

  10. 在windows 2008 R2上安装sharepoint 2013时遇到提示必须安装 .netframeword4.5的处理办法

    近日,有个客户需要个测试环境,需要搭建一个sps2013的测试服务器 但基于服务器软件授权的考虑,让使用windows2008 作为系统服务器 但一安装就碰到个提示,要求先安装framework4.5 ...