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\n",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\n",ans);
41     return 0;
42 }
View Code

 

posted @ 2013-08-20 16:18  null1019  阅读(113)  评论(0编辑  收藏  举报