标签:des style color os strong io for ar
Description
Input
Output
Sample Input
37 29 41 43 47
Sample Output
654
哈希存下一开始的两个值,看找后面三个的和,看能不能出现0
让5个for循环转化为1个双重for循环+1个三重for循环
#include <cstdio> #include <cstring> #include <algorithm> #define maxint 25000000 using namespace std; short p[25000001]; int main() { int a, b, c, d, e, i, j, k, n, s; while(scanf("%d %d %d %d %d", &a, &b, &c, &d, &e)!=EOF) { s = 0; memset(p,0,sizeof(p)); for(i = -50; i <= 50 ; i++) { if(!i) continue ; for(j=-50; j<=50; j++) { if(!j) continue ; n = i*i*i*a + j*j*j*b ; n = -n ; if(n<0) n += maxint ; p[n]++; } } for(i = -50 ; i <= 50; i++) { if(!i) continue ; for(j = -50; j <= 50; j++) { if(!j) continue ; for(k = -50; k <= 50; k++) { if(!k) continue ; n= i*i*i*c + j*j*j*d + k*k*k*e; if(n < 0) n += maxint ; if(p[n]) s += p[n]; } } } printf("%d\n",s); } return 0; }
标签:des style color os strong io for ar
原文地址:http://blog.csdn.net/winddreams/article/details/38302399