• 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;
    }

  • 相关阅读:
    Rust语言环境配置;Rust版本1.45.2学习
    《代码英雄》系列整理
    Pingcap High Performance TiDB 课程学习记录@yaowenxu
    11. C语言百钱买百鸡问题(详解版)
    10. C语言输出菱形(详解版)
    9. C语言判断素数(求素数)(两种方法)
    8. C语言求圆周率π(三种方法)
    7. C语言杨辉三角(两种方法)
    6. C语言九九乘法表(五种输出形式)
    5. C语言希尔排序算法
  • 原文地址:https://www.cnblogs.com/372465774y/p/2590679.html
Copyright © 2020-2023  润新知