• Eqs


    http://poj.org/problem?id=1840

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define MAXN 25000001
     5 using namespace std;
     6 short a[MAXN];
     7 int main()
     8 {
     9     int a1,a2,a3,a4,a5;
    10     scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
    11     memset(a,0,sizeof(a));
    12     for(int x3=-50; x3<=50; x3++)
    13     {
    14         if(!x3) continue;
    15         for(int x4=-50; x4<=50; x4++)
    16         {
    17             if(!x4) continue;
    18             for(int x5=-50; x5<=50; x5++)
    19             {
    20                 if(!x5) continue;
    21                 int sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
    22                 if(sum<0) sum+=25000000;
    23                 a[sum]++;
    24             }
    25         }
    26     }
    27     int ans=0;
    28     for(int x1=-50; x1<=50; x1++)
    29     {
    30         if(!x1) continue;
    31         for(int x2=-50; x2<=50; x2++)
    32         {
    33             if(!x2) continue;
    34             int sum=a1*x1*x1*x1+a2*x2*x2*x2;
    35             if(sum<0) sum+=25000000;
    36             ans+=a[sum];
    37         }
    38     }
    39     printf("%d
    ",ans);
    40     return 0;
    41 }
    View Code

    map做的:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<map>
     5 #define MAXN 25000001
     6 using namespace std;
     7 int main()
     8 {
     9     int a1,a2,a3,a4,a5;
    10     scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
    11     map<int,int>q;
    12     for(int x1=-50; x1<=50; x1++)
    13     {
    14         if(!x1) continue;
    15         for(int x2=-50; x2<=50; x2++)
    16         {
    17             if(!x2) continue;
    18             int sum=a1*x1*x1*x1+a2*x2*x2*x2;
    19             if(q.find(sum)==q.end())
    20             q.insert(pair<int,int>(sum,1));
    21             else q[sum]++;
    22         }
    23     }
    24     int ans=0;
    25     for(int x3=-50; x3<=50; x3++)
    26     {
    27         if(!x3) continue;
    28         for(int x4=-50; x4<=50; x4++)
    29         {
    30             if(!x4) continue;
    31             for(int x5=-50; x5<=50; x5++)
    32             {
    33                 if(!x5) continue;
    34                 int sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
    35                 if(q.find(sum)==q.end()) continue;
    36                 ans+=q[0-sum];
    37             }
    38         }
    39     }
    40     printf("%d
    ",ans);
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    C# log4net
    C# compare different Encoding pattern between UTF8 and UTF32 based on Md5
    C# extract img url from web content then download the img
    C# while loop Running until user press key
    C# GZip Compress DeCompress
    C# get md5 from bytes
    transition结合:after,:before实现动画
    http跟https的区别
    window,getComputedStyle,letter-spacing
    inline-block,vertical-align:middle
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3270423.html
Copyright © 2020-2023  润新知