Source code for submission s1258

Go to diff to previous submission

mosquito.cpp

  1. //
  2. // File: mosquito.cc
  3. // Author: cteam035
  4. //
  5. // Created on October 27, 2012, 11:23 AM
  6. //
  7.  
  8. #include <cstdlib>
  9. #include <cmath>
  10. #include <iostream>
  11. using namespace std;
  12. //
  13. //
  14. //
  15.  
  16. long long int max3 (long long int a, long long int b, long long int c) {
  17. int max;
  18. max = a>b?a:b;
  19. max = max>c?max:c;
  20. return max;
  21. }
  22.  
  23. int main(int argc, char** argv) {
  24.  
  25. long long int M,P,L,E,R,S,N;
  26. long long int a, out, max, e1, e2, e3;
  27. a=0;
  28. while ( cin >> M >> P >> L >> E >> R >> S >> N ) {
  29. switch (N%3){
  30. case 0:
  31. a=M;
  32. break;
  33. case 1:
  34. a=P;
  35. break;
  36. case 2:
  37. a=L;
  38. break;
  39. }
  40. out = a;
  41. e1 = (N/3);
  42. e2 = (long long int)ceil((1.0*N-1)/3);
  43. e3 = (long long int)ceil(1.0*N/3);
  44. max = max3(e1,e2,e3);
  45. for ( long long int i=0; i<max; i++ ) {
  46. if ( i < e1 )
  47. out *= E;
  48. if ( i < e2 )
  49. out = ( out/R );
  50. if ( i < e3 )
  51. out = ( out/S );
  52. }
  53. cout << out << endl;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. return (EXIT_SUCCESS);
  60. }
  61.  
  62.  

Diff to submission s697

mosquito.cpp

--- c4.s697.cteam035.mosquito.cpp.0.mosquito.cpp
+++ c4.s1258.cteam035.mosquito.cpp.0.mosquito.cpp
@@ -14,5 +14,5 @@
 //
 
-int max3 (int a, int b, int c) {
+long long int max3 (long long int a, long long int b, long long int c) {
     int max;
     max = a>b?a:b;
@@ -23,7 +23,7 @@
 int main(int argc, char** argv) {
     
-    int M,P,L,E,R,S,N;
-    double a=0;
-    long long int out, max, e1, e2, e3;
+    long long int M,P,L,E,R,S,N;
+    long long int a, out, max, e1, e2, e3;
+    a=0;
     while ( cin >> M >> P >> L >> E >> R >> S >> N ) {
         switch (N%3){
@@ -39,22 +39,16 @@
         }
         out = a;
-        e1=(N/3);
-        e2=ceil((1.0*N-1)/3);
-        e3=ceil(1.0*N/3);
+        e1 = (N/3);
+        e2 = (long long int)ceil((1.0*N-1)/3);
+        e3 = (long long int)ceil(1.0*N/3);
         max = max3(e1,e2,e3);
-        for ( int i=0; i<max; i++  ) {
+        for ( long long int i=0; i<max; i++  ) {
             if ( i < e1 )
                 out *= E;
             if ( i < e2 )
-                out /= R;
+                out = ( out/R );
             if ( i < e3 )
-                out /= S;
+                out = ( out/S );
         }
-//        b=pow(E,);
-//        cout << b << " " << c << " " << d << " " << endl;
-//        c=pow(R,ceil((1.0*N-1)/3));
-//        cout << b << " " << c << " " << d << " " << endl;
-//        d=pow(S,ceil(1.0*N/3));
-//        cout << b << " " << c << " " << d << " " << endl;
         cout << out << endl;
     }