• 9.3.8 Equations


    Equations

    Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 50 Accepted Submission(s): 36

    Problem Description
    Consider equations having the following form:

    a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
    a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.

    It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.

    Determine how many solutions satisfy the given equation.
     

    Input
    The input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
    End of file.
     

    Output
    For each test case, output a single line containing the number of the solutions.
     

    Sample Input
    1 2 3 -4
    1 1 1 1
     

    Sample Output
    39088
    0

    思路:Hash

    分两部分Hash,完了

    最后结果*16 因为每个数正负都可以,2^4=16

     1 /*
     2 Author:wuhuajun
     3 */
     4 #include <cmath>
     5 #include <cstdio>
     6 #include <algorithm>
     7 #include <cstring>
     8 #include <string>
     9 #include <cstdlib>
    10 using namespace std;
    11 
    12 typedef long long ll;
    13 typedef double dd;
    14 const int maxn=2000010;
    15 int ff[maxn];
    16 int *f=ff+1000003;
    17 int a,b,c,d,sum,cnt,ans;
    18 
    19 void close()
    20 {
    21 exit(0);
    22 }
    23 
    24 
    25 void init()
    26 {
    27     while (scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    28     {
    29         if (a>0 && b>0 && c>0 && d>0)
    30         {
    31             printf("0
    ");
    32             continue;
    33         }
    34         if (a<0 && b<0 && c<0 && d<0)
    35         {
    36             printf("0
    ");
    37             continue;
    38         }
    39         memset(ff,0,sizeof(ff));
    40         for (int x1=1;x1<=100;x1++)
    41         {
    42             if (x1==0) continue;
    43             for (int x2=1;x2<=100;x2++)
    44             {
    45                 if (x2==0) continue;
    46                 //printf("%d
    ",a*x1*x1+b*x2*x2);
    47                 f[a*x1*x1+b*x2*x2]++;
    48             }
    49         }
    50         ans=0;
    51         for (int x3=1;x3<=100;x3++)
    52         {
    53             if (x3==0) continue;
    54             for (int x4=1;x4<=100;x4++)
    55             {
    56                 if (x4==0) continue;
    57                 sum=c*x3*x3+d*x4*x4;
    58                 //printf("x3:%d x4:%d sum:%d
    ",x3,x4,sum);
    59                 ans+=f[-sum]*16;
    60             }
    61         }
    62         printf("%d
    ",ans);
    63     }
    64 }
    65 
    66 int main ()
    67 {
    68     init();
    69     close();
    70     return 0;
    71 }
  • 相关阅读:
    springboot与mybatisplus集成原理
    《金字塔原理》读书笔记
    域内LDAP学习
    域内委派攻击
    域内ACL攻防
    域内用户与机器用户
    BloodHound分析域结构
    Net MVC内存马
    计算机网络再次整理————socket[一]
    计算机网络再次整理————tcp例子[五]
  • 原文地址:https://www.cnblogs.com/cssystem/p/3335172.html
Copyright © 2020-2023  润新知