Ural 1246. Tethered Dog

Source: Internet
Author: User

1246. Tethered DogTime limit:1.0 Second
Memory limit:64 MBA Dog is tethered to a pole with a rope. The pole is located inside a fenced polygon, not necessarily convex, with nonzero area. The fence has no self-crosses. The Olympian runs along the fence bypassing the vertices of the polygon in a certain order which are not broken during the Jog. A Dog pursues him inside the fenced territory and barks. Your program was to determine how (clockwise or counter-clockwise) the rope would wind after several rounds of the Olympian ' S jog. Inputthe first input line contains a number NThat's the number of the polygon vertices. It ' s known that 3≤ N≤200000. The next NLines consist of the vertices plane coordinates, given in an order of Olympian ' s dog. The coordinates is a pair of integers separated with a space. The absolute value of each coordinate doesn ' t exceed 50000.OutputYou was to output "CW" If the rope is winded in a clockw Ise Order and "CCW" otherwise. Sample
input Output
40 00 11) 11 0
cw
problem Author:Evgeny Kobzev
problem Source:Ural State University Personal Programming Contest, March 1, 2003 Tags:Geometry()difficulty:364 Test Instructions: Ask if the given order of a polygon is clockwise. Analysis: Cross product judgment direction. Use the leftmost or most optimal point as the datum point.
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <deque>6#include <vector>7#include <queue>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <ctime> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; -typedefDoubleDB; - #defineFor (I, S, T) for (int i = (s); I <= (t); i++) - #defineFord (I, S, T) for (int i = (s); I >= (t); i--) + #defineRep (i, T) for (int i = (0); i < (t); i++) - #defineREPN (i, T) for (int i = (t)-1); I >= (0); i--) + #defineRep (i, X, T) for (int i = (x); i < (t); i++) A #defineMIT (2147483647) at #defineINF (1000000001) - #defineMLL (1000000000000000001LL) - #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back in #definePOF Pop_front - #definePOB pop_back to #defineFT first + #defineSD Second - #defineMk Make_pair theInlinevoidSetio (stringName) * { $     stringInput = name+". in",Panax NotoginsengOutput = name+". out"; -Freopen (Input.c_str (),"R", stdin), theFreopen (Output.c_str (),"W", stdout); + } A  theInlineintGetint () + { -     intRet =0; $     CharCh =' '; $     BOOLFlag =0; -      while(! (Ch >='0'&& Ch <='9')) -     { the         if(Ch = ='-') Flag ^=1; -Ch =GetChar ();Wuyi     } the      while(Ch >='0'&& Ch <='9') -     { WuRET = RET *Ten+ Ch-'0'; -Ch =GetChar (); About     } $     returnFlag? -Ret:ret; - } -  - Const intN =200010; A struct Point + { the DB x, y; -InlinevoidRead () $     { thescanf"%LF%LF", &x, &y); the     } the } Arr[n]; the intN; -  inInlinevoidInput () the { thescanf"%d", &n); Aboutfor (I,1, N) Arr[i]. Read (); the } the  theInline DB Det (ConstPoint &a,ConstPoint &o,ConstPoint &B) + { -DB X1 = a.x-o.x, X2 = b.x-o.x; theDB Y1 = a.y-o.y, Y2 = b.y-o.y;Bayi     returnX1 * Y2-X2 *Y1; the } the  -InlinevoidSolve () - { the     intp =1; thefor (I,2, N) the         if(arr[i].x > arr[p].x) p =i; thearr[0] = Arr[n], arr[n +1] = arr[1]; -     if(Det (Arr[p-1], Arr[p], arr[p +1]) >=0.0) puts ("CW"); the     ElsePuts"CCW"); the } the 94 intMain () the { the #ifndef Online_judge theSetio ("E");98     #endif  About Input (); - Solve ();101     return 0;102}
View Code

Ural 1246. Tethered Dog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.