Codeforces 659D Bicycle Race
Description: Bikes are only four directions down, left and right, and if the inner corner is greater than or equal to 270 degrees, the bike will drop out of the sea.
Travel by bike, the first point is the starting point coordinates, the last point or the starting point coordinates (indicating that the bicycle around a circle and back), asked how many times in the course of the ride off the sea?
God Come on, it's not. Sure enough, the nest is too weak.
Solution:
1. Simplicity.
Cross product: Look at the angle of two vectors, if the angle is less than 90 degrees, then straight away will fall into the water.
1#include <cstdio>2 Const intMAXN = ++5;3 intX[MAXN], Y[MAXN];4 #defineSA (m) scanf ("%d", &m)5 intJudgeintX1,intY1,intX2,intY2,intX3,inty3)6 {7 return(x2-x1) * (y3-y2)-(y2-y1) * (X3-X2) >0;8 9 }Ten intMain (void) One { A intN;sa (n); - intA, B; - for(inti =0; I <= N; i++){ the SA (x[i]); SA (Y[i]); - } - intres =0; - for(inti =1; I < n; i++){ +Res + = Judge (X[i-1], Y[i-1], X[i], y[i], X[i +1], Y[i +1]); - } +printf"%d\n", res); A return 0; at}I didn't write the code.
2. Mathematics. God This is faster. The code is simple.
Minus four sides of the vertical level, the intersection of each of the remaining two edges is the answer.
Because it is a right angle turn, so the internal angle is either 90 degrees, or 270 degrees, set 270 of the number of corners is x, then the equation is n-2 * (* *) = * x + (n-x) * 90; Simplification: x = (n-4)/2;
Slag Code:
1#include <stdio.h>2#include <iostream>3 using namespacestd;4 intN, a, B;5 intMain ()6 {7scanf"%d", &n);8printf"%d\n", (N-4)/2);9 return 0;Ten}Slag Code
--------------------------------
Qaqaqaq will be 8.11 soon, Qaqqaq.
I haven't even written it yet, and I don't have a tree qaq.
Shame Qaq
Codeforces 659D Bicycle Race