Source code for submission s888

Go to diff to previous submission

fo.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <algorithm>
  4. using namespace std;
  5. #include <math.h>
  6. #define REP(A,B) for(int A=0; A<B;A++)
  7. int X[11111], Y[11111];
  8. double XX[11111], YY[11111];
  9. double Q[11111];
  10. double L[11111];
  11. int main() {
  12. int N;
  13. while(scanf("%d", &N) == 1) {
  14. double ans = 10e12;
  15. REP(i, N) {
  16. scanf("%d %d", X+i, Y+i);
  17. L[i] = sqrt((double)X[i]*X[i]+(double)Y[i]*Y[i]);
  18. Q[i] = atan2(Y[i], X[i]);
  19. }
  20.  
  21. for(double ang = 0; ang < 90; ang+=0.5) {
  22. REP(i, N) {
  23. XX[i] = L[i]*cos(Q[i]+ang*M_PI/180);
  24. YY[i] = L[i]*sin(Q[i]+ang*M_PI/180);
  25. }
  26. double xmin=20000,xmax=-20000,ymin=20000,ymax=-20000;
  27. REP(i, N) {
  28. xmin = min(XX[i], xmin);
  29. xmax = max(XX[i], xmax);
  30. ymin = min(YY[i], ymin);
  31. ymax = max(YY[i], ymax);
  32. }
  33. double curr = 2*(xmax-xmin+ymax-ymin);
  34. if(curr < ans) {
  35. ans = curr;
  36. //printf("%lf\n", ang);
  37. }
  38. // printf("for ang=%lf: %lf\n", ang, 2*(xmax-xmin+ymax-ymin));
  39. }
  40. printf("%.6lf\n", ans);
  41. }
  42. return 0;
  43. }
  44.  

Diff to submission s854

fo.cpp

--- c5.s854.cteam042.fo.cpp.0.fo.cpp
+++ c5.s888.cteam042.fo.cpp.0.fo.cpp
@@ -7,16 +7,20 @@
 int X[11111], Y[11111];
 double XX[11111], YY[11111];
+double Q[11111];
+double L[11111];
 int main() {
         int N;
         while(scanf("%d", &N) == 1) {
                 double ans = 10e12;
-                REP(i, N) scanf("%d %d", X+i, Y+i);
-                for(double ang = 0; ang < 90; ang+=0.05) {
+                REP(i, N) {
+                        scanf("%d %d", X+i, Y+i);
+                        L[i] = sqrt((double)X[i]*X[i]+(double)Y[i]*Y[i]);
+                        Q[i] = atan2(Y[i], X[i]);
+                }
+
+                for(double ang = 0; ang < 90; ang+=0.5) {
                         REP(i, N) {
-                                double q = atan2(Y[i], X[i]);
-                                double len = sqrt((double)X[i]*X[i]+(double)Y[i]*Y[i]);
-                                q+=ang;
-                                XX[i] = len*cos(q);
-                                YY[i] = len*sin(q);
+                                XX[i] = L[i]*cos(Q[i]+ang*M_PI/180);
+                                YY[i] = L[i]*sin(Q[i]+ang*M_PI/180);
                         }
                         double xmin=20000,xmax=-20000,ymin=20000,ymax=-20000;
@@ -27,5 +31,9 @@
                                 ymax = max(YY[i], ymax);
                         }
-                        ans = min(2*(xmax-xmin+ymax-ymin), ans);
+                        double curr = 2*(xmax-xmin+ymax-ymin);
+                        if(curr < ans) {
+                                ans = curr;
+                                //printf("%lf\n", ang);
+                        }
 //                      printf("for ang=%lf: %lf\n", ang, 2*(xmax-xmin+ymax-ymin));
                 }