Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 14101 | Accepted: 6932 |
map水一发;
Description
Input
Output
Sample Input
37 29 41 43 47
Sample Output
654
Source
Source Code Problem: 1840 User: 14110103069 Memory: 1208K Time: 2000MS Language: G++ Result: Accepted Source Code #include <iostream> #include<cstring> #include<cstdio> #include<queue> #include<stack> #include<cmath> #include<map> #include<algorithm> #define LL long long using namespace std; int main() { LL a,b,x,y,z; LL tmp; map<int,LL>Q; while(~scanf("%lld%lld%lld%lld%lld",&a,&b,&x,&y,&z)) { Q.clear(); for(int i=-50;i<=50;i++) { if(i==0)continue; for(int j=-50;j<=50;j++) { if(j==0) continue; tmp=a*i*i*i+b*j*j*j; Q[-tmp]++; } } LL ans=0; for(int i=-50;i<=50;i++) { if(i==0)continue; for(int j=-50;j<=50;j++) { if(j==0) continue; for(int k=-50;k<=50;k++) { if(k==0 )continue; tmp=x*i*i*i+y*j*j*j+z*k*k*k; if(Q.count(tmp)) { ans+=Q[tmp]; } } } } printf("%lld\n",ans); } return 0; }数组哈希:
Source Code Problem: 1840 User: 14110103069 Memory: 49112K Time: 547MS Language: C++ Result: Accepted Source Code #include <iostream> #include<cstring> #include<cstdio> #include<queue> #include<stack> #include<cmath> #include<algorithm> using namespace std; short hx[25000000]; int main() { int a1,a2,a3,a4,a5; while(~scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)) { int g; memset(hx,0,sizeof(hx)); for(int i=-50; i<=50; i++) { if(!i) continue; for(int j=-50; j<=50; j++) { if(!j) continue; g=(a1*(i*i*i)+a2*(j*j*j))*(-1); if(g<0) g+=25000000; hx[g]++; } } int ans=0; for(int i=-50; i<=50; i++) { if(!i) continue; for(int j=-50; j<=50; j++) { if(!j) continue; for(int l=-50; l<=50; l++) { if(!l) continue; g=(a3*(i*i*i)+a4*(j*j*j)+a5*(l*l*l)); if(g<0) g+=25000000; ans+=hx[g]; } } } printf("%d\n",ans); } return 0; }