fork download
  1. // C Library
  2. #include <cassert> // (assert.h) C Diagnostics Library (header)
  3. #include <cctype> // (ctype.h) Character handling functions (header)
  4. #include <cerrno> // (errno.h) C Errors (header)
  5. #include <cfloat> // (float.h) Characteristics of floating-point types (header)
  6. #include <ciso646> // (iso646.h) ISO 646 Alternative operator spellings (header)
  7. #include <climits> // (limits.h) Sizes of integral types (header)
  8. #include <clocale> // (locale.h) C localization library (header)
  9. #include <cmath> // (math.h) C numerics library (header)
  10. #include <csetjmp> // (setjmp.h) Non local jumps (header)
  11. #include <csignal> // (signal.h) C library to handle signals (header)
  12. #include <cstdarg> // (stdarg.h) Variable arguments handling (header)
  13. #include <cstdbool> // (stdbool.h) Boolean type (header)
  14. #include <cstddef> // (stddef.h) C Standard definitions (header)
  15. #include <cstdint> // (stdint.h) Integer types (header)
  16. #include <cstdio> // (stdio.h) C library to perform Input/Output operations (header)
  17. #include <cstdlib> // (stdlib.h) C Standard General Utilities Library (header)
  18. #include <cstring> // (string.h) C Strings (header)
  19. #include <ctime> // (time.h) C Time Library (header)
  20. //#include <cuchar> // (uchar.h) Unicode characters (header)
  21. #include <cwchar> // (wchar.h) Wide characters (header)
  22. #include <cwctype> // (wctype.h) Wide character type (header)
  23.  
  24. // Containers
  25. #include <array> // Array header (header)
  26. #include <bitset> // Bitset header (header)
  27. #include <deque> // Deque header (header)
  28. #include <forward_list> // Forward list (header)
  29. #include <list> // List header (header)
  30. #include <map> // Map header (header)
  31. #include <queue> // Queue header (header)
  32. #include <set> // Set header (header)
  33. #include <stack> // Stack header (header)
  34. #include <unordered_map> //Unordered map header (header)
  35. #include <unordered_set> // Unordered set header (header)
  36. #include <vector> // Vector header (header)
  37.  
  38. // Input/Output Stream Library
  39. #include <iostream> // The class relies on a single streambuf object for both the input and output operations.
  40. #include <fstream> // Input/output stream class to operate on files.
  41. #include <sstream> //
  42.  
  43. // Miscellaneous headers
  44. #include <algorithm> // Standard Template Library: Algorithms (library )
  45. #include <chrono> // Time library (header)
  46. //#include <codecvt> // Unicode conversion facets (header)
  47. #include <complex> // Complex numbers library (header)
  48. #include <exception> // Standard exceptions (header)
  49. #include <functional> // Function objects (header)
  50. #include <initializer_list> // Initializer list (header)
  51. #include <iterator> // Iterator definitions (header)
  52. #include <limits> // Numeric limits (header)
  53. #include <locale> // Localization library (header)
  54. #include <memory> //Memory elements (header)
  55. #include <new> // Dynamic memory (header)
  56. #include <numeric> // Generalized numeric operations (header)
  57. #include <random> // Random (header)
  58. #include <ratio> // Ratio header (header)
  59. #include <regex> // Regular Expressions (header)
  60. #include <stdexcept> // Exception classes (header)
  61. #include <string> // Strings (header)
  62. #include <system_error> // System errors (header)
  63. #include <tuple> // Tuple library (header)
  64. #include <typeinfo> // Type information (header)
  65. #include <type_traits> //type_traits (header)
  66. #include <utility> // Utility components (header)
  67. #include <valarray> // Library for arrays of numeric values (header)
  68. #include <iomanip> // Header providing parametric manipulators
  69.  
  70. using namespace std;
  71.  
  72. struct point
  73. {
  74. int x;
  75. int y;
  76. };
  77.  
  78. int main( int argc, char **argv )
  79. {
  80. int W, H, N;
  81. cin >> W >> H >> N;
  82. vector<struct point> points(N);
  83. for ( int i = 0 ; i < N ; ++i )
  84. {
  85. cin >> points[i].x >> points[i].y;
  86. }
  87. int num_road = 0;
  88. for ( int i = 0 ; i < N - 1 ; ++i )
  89. {
  90. if ( points[i].x == points[i+1].x ||
  91. points[i].y == points[i+1].y )
  92. {
  93. int tmp_road = abs( points[i].x - points[i+1].x ) + abs( points[i].y - points[i+1].y );
  94. //cout << "first" << endl;
  95. //cout << tmp_road << endl;
  96. num_road += tmp_road;
  97. }
  98. // NE, SW
  99. else if ( ( points[i].x < points[i+1].x && points[i].y < points[i+1].y ) ||
  100. ( points[i].x > points[i+1].x && points[i].y > points[i+1].y ) )
  101. {
  102. int tmp_road = max( abs( points[i].x - points[i+1].x ), abs( points[i].y - points[i+1].y ) );
  103. //cout << "second" << endl;
  104. //cout << tmp_road << endl;
  105. num_road += tmp_road;
  106. }
  107. // NW, SE
  108. else if ( ( points[i].x < points[i+1].x && points[i].y > points[i+1].y ) ||
  109. ( points[i].x > points[i+1].x && points[i].y < points[i+1].y ) )
  110. {
  111. int tmp_road = abs(points[i].x - points[i+1].x) + abs(points[i].y - points[i+1].y);
  112. //cout << "third" << endl;
  113. //cout << tmp_road << endl;
  114. num_road += tmp_road;
  115. }
  116. }
  117. cout << num_road << endl;
  118. return EXIT_SUCCESS;
  119. }
  120.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0