Poj 1840 Eqs

Poj 1840 Eqs

题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1840
题目描述:求方程的根的个数
注意事项:hash可以用char,避免占用内存过多
提交情况:1次MLE,用int开数组太大了
心得体会:暂无
 1  #include < stdio.h >
 2  #include < string .h >
 3 
 4  int  calCube( int  x)
 5  {
 6       return  x * x * x;
 7  }
 8 
 9  char  hash[ 25000010 ];
10 
11  int  main()
12  {
13       int  a1,a2,a3,a4,a5;
14      scanf( " %d%d%d%d%d " , & a1, & a2, & a3, & a4, & a5);
15 
16       int  result;
17      memset(hash, 0 , sizeof (hash));
18       for ( int  i =- 50 ;i <= 50 ;i ++ )
19      {
20           if (i == 0 )
21               continue ;
22           for ( int  j =- 50 ;j <= 50 ;j ++ )
23          {
24               if (j == 0 )
25                   continue ;
26               for ( int  k =- 50 ;k <= 50 ;k ++ )
27              {
28                   if (k == 0 )
29                       continue ;
30                  result = a1 * calCube(i) + a2 * calCube(j) + a3 * calCube(k);
31                   if (result > 12500000 || result <- 12500000 )
32                       continue ;
33                  hash[result + 12500000 ] ++ ;
34              }
35          }
36      }
37 
38       int  ans = 0 ;
39       for ( int  i =- 50 ;i <= 50 ;i ++ )
40      {
41           if (i == 0 )
42               continue ;
43           for ( int  j =- 50 ;j <= 50 ;j ++ )
44          {
45               if (j == 0 )
46                   continue ;
47              result = a4 * calCube(i) + a5 * calCube(j);
48              result =- result;
49              ans += hash[result + 12500000 ];
50          }
51      }
52 
53      printf( " %d\n " ,ans);
54  }

你可能感兴趣的:(Poj 1840 Eqs)