This is really too embarrassing. I almost did this. It is clearly a template question. How can I make it wrong, I handed in more than a dozen or even 20 times or WA ................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ................................................................................ ........................................ ........................................ ........................................ ..... ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ............................... ........................... ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ................................................................................ ........................................ ........................................ ........................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ................................. One morning passed ............................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ............................................................................................................... ....................................................................................... After dinner, of course, I still don't want to be reconciled. I suddenly saw it in other people's code. when there were only two points, I had to calculate one side. Then I was so embarrassed ............ This is the result.
Annoying, not explained, not written
# Include <iostream> # include <vector> # include <algorithm> # include <stack> # include <cmath> using namespace STD; Class cor {public: int X, Y ;}; cor start; bool drection (Cor & P0, Cor & P1, Cor & p2) {int X1 = p1.x-1_x; int Y1 = p1.y-1_y; int X2 = p2.x-branch X; int y2 = p2.y-branch y; If (X2 * y1-x1 * Y2> 0) return true; return false;} bool CMP (Cor & LHS, cor & RHs) {return drection (START, RHS, LHS);} double calc (Cor P1, Cor P2) {double A = POW (double) (p1.x-p2.x ), 2); Double B = POW (double) (p1.y-p2.y), 2); Return SQRT (a + B);} int main () {int NTree; while (CIN> NTree & NTree) {vector <cor> trees; stack <cor> CH; CIN> Start. x> Start. y; For (INT I = 1; I <NTree; I ++) {cor P; CIN> P. x> P. y; If (P. Y <start. y) {trees. push_back (start); Start = P;} else if (P. y = start. Y & P. x <start. x) {trees. push_back (start); Start = P;} else trees. push_back (p);} If (NTree = 1) {printf ("0.00 \ n"); continue;} If (NTree = 2) {printf ("%. 2lf \ n ", Calc (START, trees [0]); continue;} Sort (trees. begin (), trees. end (), CMP); Ch. push (start); Ch. push (trees [0]); Ch. push (trees [1]); For (vector <cor >:: size_type I = 2; I <trees. size (); I ++) {cor P0, P1, P2; P1 = CH. top (); Ch. pop (); p0 = CH. top (); Ch. push (P1); // get the element P2 = trees [I] at the top of the stack; while (drection (P0, P1, P2) {ch. pop (); P1 = CH. top (); Ch. pop (); p0 = CH. top (); Ch. push (P1); // obtain the top and bottom elements of the stack} ch. push (P2) ;}double Len = 0.0; Cor P1, P2; Ch. push (start); P1 = CH. top (); P2 = p1; stack <cor >:: size_type K = CH. size (); For (stack <cor >:: size_type I = 1; I <K; I ++) {ch. pop (); P2 = CH. top (); Len + = calc (P1, P2); P1 = P2;} printf ("%. 2lf \ n ", Len);} return 0 ;}