main.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. using namespace std;
  7. const int N = 1000;
  8. struct Point {
  9. int x;
  10. int y;
  11. Point(int x = 0, int y = 0) : x(x), y(y) {}
  12. bool operator<(const Point& that) const {
  13. if (this->x == that.x) return this->y < that.y;
  14. return this->x < that.x;
  15. }
  16. Point operator-(const Point& that) const {
  17. return Point(this->x - that.x, this->y - that.y);
  18. }
  19. int operator^(const Point& that) const {
  20. return this->x * that.y - this->y * that.x;
  21. }
  22. } point[N];
  23. double dist(const Point& a, const Point& b) {
  24. int dx = a.x - b.x;
  25. int dy = a.y - b.y;
  26. return sqrt((double)dx * dx + dy * dy);
  27. }
  28. int main() {
  29. int n, l;
  30. scanf("%d %d", &n, &l);
  31. for (int i = 0; i < n; i++) scanf("%d %d", &point[i].x, &point[i].y);
  32. sort(point, point + n);
  33. vector<Point> stack;
  34. stack.push_back(point[0]);
  35. stack.push_back(point[1]);
  36. for (int i = 2; i < n; i++) {
  37. Point& p = point[i];
  38. while (1 < stack.size()) {
  39. Point p1 = *(stack.end() - 1);
  40. Point p2 = *(stack.end() - 2);
  41. if (((p2 - p1) ^ (p - p2)) < 0)
  42. stack.pop_back();
  43. else
  44. break;
  45. }
  46. stack.push_back(p);
  47. }
  48. double len = 0.;
  49. Point pre = *(stack.begin());
  50. vector<Point>::iterator it;
  51. for (it = ++stack.begin(); it != stack.end(); ++it) {
  52. len += dist(pre, *it);
  53. pre = *it;
  54. }
  55. stack.clear();
  56. stack.push_back(point[n - 1]);
  57. stack.push_back(point[n - 2]);
  58. for (int i = n - 3; 0 <= i; i--) {
  59. Point& p = point[i];
  60. while (1 < stack.size()) {
  61. Point p1 = *(stack.end() - 1);
  62. Point p2 = *(stack.end() - 2);
  63. if (((p2 - p1) ^ (p - p2)) < 0)
  64. stack.pop_back();
  65. else
  66. break;
  67. }
  68. stack.push_back(p);
  69. }
  70. pre = *(stack.begin());
  71. for (it = ++stack.begin(); it != stack.end(); ++it) {
  72. len += dist(pre, *it);
  73. pre = *it;
  74. }
  75. printf("%.0lf\n", len + acos(-1.) * l * 2);
  76. return 0;
  77. }