main.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. int size = stack.size();
  49. stack.push_back(point[n - 2]);
  50. for (int i = n - 3; 0 <= i; i--) {
  51. Point& p = point[i];
  52. while (size < stack.size()) {
  53. Point p1 = *(stack.end() - 1);
  54. Point p2 = *(stack.end() - 2);
  55. if (((p2 - p1) ^ (p - p2)) < 0)
  56. stack.pop_back();
  57. else
  58. break;
  59. }
  60. stack.push_back(p);
  61. }
  62. double len = 0.;
  63. Point pre = *(stack.begin());
  64. vector<Point>::iterator it;
  65. for (it = ++stack.begin(); it != stack.end(); ++it) {
  66. len += dist(pre, *it);
  67. pre = *it;
  68. }
  69. printf("%.0lf\n", len + acos(-1.) * l * 2);
  70. return 0;
  71. }