Go to diff to previous submission
#include <stdio.h> #include <stdlib.h> #include <algorithm> using namespace std; #include <math.h> #define REP(A,B) for(int A=0; A<B;A++) 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); 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) { 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; REP(i, N) { xmin = min(XX[i], xmin); xmax = max(XX[i], xmax); ymin = min(YY[i], ymin); ymax = max(YY[i], ymax); } 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)); } printf("%.6lf\n", ans); } return 0; }
--- 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)); }