Eqs

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15029

题意:

给出系数a1,a2,a3,a4,a5,求出方程a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 有多少个解。

样例:

Sample Input

37 29 41 43 47

Sample Output

654

分析:
如果直接用5个for循环是会超时的,所以把方程a1x1x1x1+a2x2x2x2+a3x3x3x3+a4x4x4x4+a5x5x5x5=0
转变成-(a1x1x1x1+a2x2x2x2)=a3x3x3x3+a4x4x4x4+a5x5x5x5这样就将5层循环减少到3层循环。
 #include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=;
int i,a[],count=,sum=;
short b[maxn];
int x1,x2,x3,x4,x5;
int main()
{
memset(b,,sizeof(b));
for(i=;i<;i++)
cin>>a[i];
for(x1=-;x1<=;x1++)
{ if(x1==) continue;
for(x2=-;x2<=;x2++)
{
if(x2==) continue;
sum=-*(a[]*x1*x1*x1+a[]*x2*x2*x2);
if(sum<)
b[maxn+sum]++;
else b[sum]++;
}
}
for(x3=-;x3<=;x3++)
{
if(x3==) continue;
for(x4=-;x4<=;x4++)
{
if(x4==) continue;
for(x5=-;x5<=;x5++)
{
if(x5==) continue;
sum=a[]*x3*x3*x3+a[]*x4*x4*x4+a[]*x5*x5*x5;
if(sum<)
sum=maxn+sum;
count=count+b[sum];
} }
}
cout<<count<<endl;
return ;
}
 

 

Eqs的更多相关文章

  1. POJ 1840 Eqs

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

  2. 【POJ】1840:Eqs【哈希表】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18299   Accepted: 8933 Description ...

  3. 測试赛C - Eqs(哈希)

    C - Eqs Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

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

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

  5. POJ 1840 Eqs(hash)

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

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

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

  7. POJ1840 Eqs

    题意描述 Eqs 求一个五元方程 \(a_1x_1^3+a_2x_2^3+a_3x_3^3+a_4x_4^3+a_5x_5^3=0\) 的解的个数. 题中给出 \(a_i\) 的值并且保证 \(-50 ...

  8. POJ 1840 Eqs 二分+map/hash

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

  9. POJ 1840 Eqs 暴力

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

随机推荐

  1. WPF ListView展示层叠信息

    通常我们在ListView中展示一列同类数据,例如城市名称.不过可以对ListView的DataTemplate稍作修改,让其显示层叠信息.例如:需要在ListView中显示省份和省份对应的城市名称. ...

  2. 从github下载某个git库的4种方法

    转自:http://blog.csdn.net/feiniao1221/article/details/7516421 以gerrit-trigger-plugin为例,下面的链接都是从相应页面上直接 ...

  3. C++Primer快速浏览笔记-类型转换

    bool b = 42; // _b is true_ int i = b; // _i has value 1_ i = 3.14; // _i has value 3_ double pi = i ...

  4. ARM指令学习,王明学learn

    ARM指令学习 一.算数和逻辑指令 1— MOV 数据传送指令    2.— MVN 数据取反传送指令    3.— CMP 比较指令    4.— CMN 反值比较指令    5.— TST 位测试 ...

  5. jquery audio player

    <!DOCTYPE html><html lang="en"> <head>  <meta charset="utf-8&quo ...

  6. Axure 全局辅助线(转)

    普通辅助线作用于当前页 全局作用于所有页面 , 包括新建页面 创建普通辅助线直接拉出来 创建全局辅助线 , 在拉出来的时候按住 Ctrl 默认情况下 , 颜色不同 辅助线可以多选 , 用拖选 或 按 ...

  7. 在Salesforce中创建Web Service供外部系统调用

    在Salesforce中可以创建Web Service供外部系统调用,并且可以以SOAP或者REST方式向外提供调用接口,接下来的内容将详细讲述一下用SOAP的方式创建Web Service并且用As ...

  8. waterMarkTextBox

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  9. loj 1210 (求最少的加边数使得图变成强连通)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1210 思路:首先是缩点染色,然后重建并且统计新图中的每个点的入度和出度,于是答案就是m ...

  10. 如何离线下载Chrome的安装包

    打开Chrome官网(自行搜索)点击下载后下载的是联网安装包,这对部分上网不方便的用户造成了一定的麻烦. http://www.google.cn/chrome/browser/desktop/ind ...