zoukankan      html  css  js  c++  java
  • POJ 1840 Eqs

    Eqs
    Time Limit: 5000MS   Memory Limit: 65536K
    Total Submissions: 8484   Accepted: 4187

    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保存一半结果 再去检测另一半

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #define Y 18750003
    using namespace std;
    char hz[Y],hf[Y];
    int main()
    {
        int a1,a2,a3,a4,a5;
        int i,j,k,n,t;
        while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)
        {
            for(i=0;i<Y;i++)
              hz[i]=hf[i]=0;
            for(i=-50;i<=50;i++)
              if(i!=0)
              {
                  for(j=-50;j<=50;j++)
                    if(j!=0)
                     {
                         for(k=-50;k<=50;k++)
                           if(k!=0)
                            {
                                t=a1*i*i*i+a2*j*j*j+a3*k*k*k;
                                if(t>=0)
                                  hz[t]++;
                                else
                                  hf[-t]++;
                            }
                     }
              }
              n=0;
            for(i=-50;i<=50;i++)
              if(i!=0)
              {
                  for(j=-50;j<=50;j++)
                    if(j!=0)
                     {
                         t=a4*i*i*i+a5*j*j*j;
                         if(t>0)
                          n+=hf[t];
                         else
                          n+=hz[-t];
                     }
              }
            printf("%d\n",n);

        }
        return 0;
    }

  • 相关阅读:
    如何快速把 Vue 项目升级到 webpack3
    10分钟学会ES7+ES8
    数组的32场演唱会
    你做的拷贝是真的深拷贝吗
    浅谈CSS模块化
    CORS跨域资源共享你该知道的事儿
    像VUE一样写微信小程序-深入研究wepy框架
    小型Web页打包优化(下)
    PT与PX区别
    px、pt和em的区别
  • 原文地址:https://www.cnblogs.com/372465774y/p/2590679.html
Copyright © 2011-2022 走看看