zoukankan      html  css  js  c++  java
  • Eqs

    题意:对于方程: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 两部分,若这两部分相等,则为方程的一个解。

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 short hash[25000002];
     5 int main(){
     6     int coff[5],base[101];
     7     int i,j,k;
     8     int result=0;
     9     for(i=0;i<5;i++){
    10         scanf("%d",&coff[i]);
    11     }
    12     for(i=-50;i<=50;i++){
    13             int tmp=i*i*i;
    14             base[i+50]=tmp;
    15     }
    16     memset(hash,0,sizeof(hash));
    17     for(i=-50;i<=50;i++){
    18         for(j=-50;j<=50;j++){
    19 
    20             if(i!=0&&j!=0){
    21                 int tmp=coff[0]*base[i+50]+coff[1]*base[j+50];
    22                 hash[tmp+12500000]++;
    23             }
    24         }
    25     }
    26 
    27     for(i=-50;i<=50;i++){
    28         for( j=-50;j<=50;j++){
    29             for(k=-50;k<=50;k++){
    30                 if(i!=0&&j!=0&&k!=0){
    31                     int tmp=coff[2]*base[i+50]+coff[3]*base[j+50]+coff[4]*base[k+50];
    32                     tmp=0-tmp;
    33                     if(tmp<12500000&&tmp>=-12500000)
    34                     result+=hash[tmp+12500000];
    35                 }
    36 
    37             }
    38 
    39         }
    40     }
    41     printf("%d
    ",result);
    42     return 0;
    43 }

    附:

    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
  • 相关阅读:
    CentOS 6.5/6.6 安装mysql 5.7 最完整版教程
    linux下的find文件查找命令与grep文件内容查找命令
    为mongodb数据库增加用户名密码权限
    mac 用密钥远程登陆
    MongoDB导入导出以及数据库备份
    ubuntu12.04上的mongodb卸载
    在Ubuntu下进行MongoDB安装步骤
    slice,substr和substring的区别
    再议js的传递和深复制
    js 参数传递
  • 原文地址:https://www.cnblogs.com/sdxk/p/4712740.html
Copyright © 2011-2022 走看看