4-point polyline
Give you a grid, from (0, 0) to (n, m ). Select four different vertices in the grid and connect them to three segments in order. Find out what the three segments want to add and the longest, and output this situation.
Thought: At that time, all kinds of egg pains occurred, mainly because I didn't think about the direction. As a result, WA had been in 3rd groups. Today I saw a clear idea.
First, determine a short edge, and m is taken as a short edge.
There are three main scenarios:
1. When the short side is 0:
2. Calculate dis1
3. Calculate dis2
4. Select the order in which the distance (2) and (3) are greater and the order of the four points is output.
/*************************************** * *********************************> File Name: cf452b. CPP> author: glsilence> created time: monday, July 28, 2014 ******************************** **************************************** /# include <stdio. h> # include <iostream> using namespace STD; int distance (INT X1, int Y1, int X2, int Y2) {return (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1);} int n, m; int x1, x2, X3, X4, Y1, Y2, Y3, Y4; int main () {scanf ("% d", & N, & M); bool change = false; If (M> N) {swap (n, m ); change = true;} If (M = 0) {x1 = 1, X2 = N, X3 = 0, X4 = n-1; Y1 = Y2 = Y3 = Y4 = 0 ;} else {int dis1 = distance (0, 0, n, m) * 2 + distance (0, 0, N, 0); int dis2 = distance (0, 0, n, m) + distance (0, 0, N m-1) * 2; If (dis1> dis2) {x1 = 0, Y1 = 0; x2 = N, y2 = m; x3 = 0, Y3 = m; X4 = N, Y4 = 0;} else {x1 = 0, Y1 = 1; x2 = N, y2 = m; X3 = 0, y3 = 0; X4 = N, Y4 = m-1;} If (Change) {swap (x1, Y1); swap (X2, Y2); swap (X3, Y3 ); swap (X4, Y4);} printf ("% d \ n", X1, y1, X2, Y2, X3, Y3, X4, Y4); Return 0 ;}