Source code for submission s1046

fo.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <map>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. typedef map<double, double> MAP;
  9. typedef MAP::iterator IT;
  10.  
  11. typedef struct POINT
  12. {
  13. int x;
  14. int y;
  15. }
  16. POINT;
  17.  
  18. typedef struct DOINT
  19. {
  20. double x;
  21. double y;
  22. }
  23. DOINT;
  24.  
  25. POINT Input[20000];
  26. DOINT Point[20000];
  27.  
  28. double Queue[1000];
  29.  
  30. int n;
  31. double GetPerimeter(double d)
  32. {
  33. d *= (atan(1) * 4) / 180.;
  34.  
  35. double xMin = 1e10, xMax = -1e10, yMin = 1e10, yMax = -1e10;
  36.  
  37. for(int i = 0; i < n; i++)
  38. {
  39. double x = Input[i].x;
  40. double y = Input[i].y;
  41.  
  42. Point[i].x = (cos(d) * x) - (sin(d) * y);
  43. Point[i].y = (sin(d) * x) + (cos(d) * y);
  44.  
  45. if(Point[i].x < xMin) xMin = Point[i].x;
  46. if(Point[i].x > xMax) xMax = Point[i].x;
  47.  
  48. if(Point[i].y < yMin) yMin = Point[i].y;
  49. if(Point[i].y > yMax) yMax = Point[i].y;
  50. }
  51.  
  52. return 2. * ((xMax - xMin) + (yMax - yMin));
  53. }
  54.  
  55. int main()
  56. {
  57. while(scanf("%d", &n) > 0)
  58. {
  59. MAP Map;
  60. Map.clear();
  61.  
  62. double rsl;
  63. for(int i = 0; i < n; i++)
  64. {
  65. scanf("%d%d", &(Input[i].x), &(Input[i].y));
  66. }
  67.  
  68. double step = 90. / 1024.;
  69. for(double d = 0.; d <= 90.; d += step)
  70. {
  71. Map[GetPerimeter(d)] = d;
  72. }
  73.  
  74. for(int k = 0; k < 10; k++)
  75. {
  76. step /= 64.;
  77. int i = 0;
  78. for(IT it = Map.begin(); i < 5; it++, i++)
  79. {
  80. Queue[i] = it->second;
  81. }
  82.  
  83. for(i = 0; i < 5; i++)
  84. {
  85. double d = Queue[i];
  86. for(int j = -64; j <= 64; j++)
  87. {
  88. double dd = d + (j * step);
  89. Map[GetPerimeter(dd)] = dd;
  90. }
  91. }
  92. }
  93.  
  94. /*for(IT it = Map.begin(); it != Map.end(); it++)
  95. {
  96. printf("%lf for %lf degrees\n", it->first, it->second);
  97. }*/
  98.  
  99. rsl = Map.begin()->first;
  100. printf("%lf\n", rsl);
  101. }
  102.  
  103. return 0;
  104. }
  105.