659D.md (3114B)
1 Source: https://codeforces.com/problemset/problem/659/D 2 3 D. Bicycle Race 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Maria participates in a bicycle race. 22 23 The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. 24 25 Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and the *Oy* axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). 26 27 Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. 28 29 Help Maria get ready for the competition — determine the number of dangerous turns on the track. 30 31 Input 32 33 The first line of the input contains an integer *n* (4 ≤ *n* ≤ 1000) — the number of straight sections of the track. 34 35 The following (*n* + 1)-th line contains pairs of integers (*x**i*, *y**i*) ( - 10 000 ≤ *x**i*, *y**i* ≤ 10 000). The first of these points is the starting position. The *i*-th straight section of the track begins at the point (*x**i*, *y**i*) and ends at the point (*x**i* + 1, *y**i* + 1). 36 37 It is guaranteed that: 38 39 * the first straight section is directed to the north; 40 * the southernmost (and if there are several, then the most western of among them) point of the track is the first point; 41 * the last point coincides with the first one (i.e., the start position); 42 * any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); 43 * no pair of points (except for the first and last one) is the same; 44 * no two adjacent straight sections are directed in the same direction or in opposite directions. 45 46 Output 47 48 Print a single integer — the number of dangerous turns on the track. 49 50 Examples 51 52 Input 53 54 ``` 55 6 56 0 0 57 0 1 58 1 1 59 1 2 60 2 2 61 2 0 62 0 0 63 ``` 64 65 Output 66 67 ``` 68 1 69 ``` 70 71 Input 72 73 ``` 74 16 75 1 1 76 1 5 77 3 5 78 3 7 79 2 7 80 2 9 81 6 9 82 6 7 83 5 7 84 5 3 85 4 3 86 4 4 87 3 4 88 3 2 89 5 2 90 5 1 91 1 1 92 ``` 93 94 Output 95 96 ``` 97 6 98 ``` 99 100 Note 101 102 The first sample corresponds to the picture: 103 104  105 106 The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.