ural 1246. Tethered Dog

1246. Tethered Dog

Time limit: 1.0 second
Memory limit: 64 MB

A 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 is not broken during the jog. A dog pursues him inside the fenced territory and barks. Your program is to determine how (clockwise or counter-clockwise) the rope will wind after several rounds of the Olympian‘s jog.

Input

The first input line contains a number N that is the number of the polygon vertices. It’s known that 3 ≤ N ≤ 200000. The next N lines consist of the vertices plane coordinates, given in an order of Olympian’s dog. The coordinates are a pair of integers separated with a space. The absolute value of each coordinate doesn’t exceed 50000.

Output

You are to output "cw", if the rope is winded in a clockwise order and "ccw" otherwise.

Sample

input output
4
0 0
0 1
1 1
1 0
cw

Problem Author: Evgeny Kobzev
Problem Source: Ural State University Personal Programming Contest, March 1, 2003

Tags: geometry  (hide tags for unsolved problems)

Difficulty: 364

题意:问一个多边形的给出顺序是不是顺时针。

分析:叉积判断方向。用最左或最优的点作为基准点。

  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>
 10 #include <map>
 11 #include <set>
 12 #include <ctime>
 13 #include <iomanip>
 14 using namespace std;
 15 typedef long long LL;
 16 typedef double DB;
 17 #define For(i, s, t) for(int i = (s); i <= (t); i++)
 18 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
 19 #define Rep(i, t) for(int i = (0); i < (t); i++)
 20 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
 21 #define rep(i, x, t) for(int i = (x); i < (t); i++)
 22 #define MIT (2147483647)
 23 #define INF (1000000001)
 24 #define MLL (1000000000000000001LL)
 25 #define sz(x) ((int) (x).size())
 26 #define clr(x, y) memset(x, y, sizeof(x))
 27 #define puf push_front
 28 #define pub push_back
 29 #define pof pop_front
 30 #define pob pop_back
 31 #define ft first
 32 #define sd second
 33 #define mk make_pair
 34 inline void SetIO(string Name)
 35 {
 36     string Input = Name+".in",
 37     Output = Name+".out";
 38     freopen(Input.c_str(), "r", stdin),
 39     freopen(Output.c_str(), "w", stdout);
 40 }
 41
 42 inline int Getint()
 43 {
 44     int Ret = 0;
 45     char Ch = ‘ ‘;
 46     bool Flag = 0;
 47     while(!(Ch >= ‘0‘ && Ch <= ‘9‘))
 48     {
 49         if(Ch == ‘-‘) Flag ^= 1;
 50         Ch = getchar();
 51     }
 52     while(Ch >= ‘0‘ && Ch <= ‘9‘)
 53     {
 54         Ret = Ret * 10 + Ch - ‘0‘;
 55         Ch = getchar();
 56     }
 57     return Flag ? -Ret : Ret;
 58 }
 59
 60 const int N = 200010;
 61 struct Point
 62 {
 63     DB x, y;
 64     inline void Read()
 65     {
 66         scanf("%lf%lf", &x, &y);
 67     }
 68 } Arr[N];
 69 int n;
 70
 71 inline void Input()
 72 {
 73     scanf("%d", &n);
 74     For(i, 1, n) Arr[i].Read();
 75 }
 76
 77 inline DB Det(const Point &A, const Point &O, const Point &B)
 78 {
 79     DB X1 = A.x - O.x, X2 = B.x - O.x;
 80     DB Y1 = A.y - O.y, Y2 = B.y - O.y;
 81     return X1 * Y2 - X2 * Y1;
 82 }
 83
 84 inline void Solve()
 85 {
 86     int p = 1;
 87     For(i, 2, n)
 88         if(Arr[i].x > Arr[p].x) p = i;
 89     Arr[0] = Arr[n], Arr[n + 1] = Arr[1];
 90     if(Det(Arr[p - 1], Arr[p], Arr[p + 1]) >= 0.0) puts("cw");
 91     else puts("ccw");
 92 }
 93
 94 int main()
 95 {
 96     #ifndef ONLINE_JUDGE
 97     SetIO("E");
 98     #endif
 99     Input();
100     Solve();
101     return 0;
102 }

时间: 2024-10-27 19:47:28

ural 1246. Tethered Dog的相关文章

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

poj2761 feed the dog

题目链接:http://poj.org/problem?id=2761 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the dogs, so Jiajia use a special way to feed the dogs. At lunchti

Java中Animal b = new Dog();Dog c = new Dog();的区别

由于在编译阶段,只是检查参数的引用类型.然而在运行时,Java虚拟机(JVM)指定对象的类型并且运行该对象的方法.因此在下面的例子中,b.move()之所以能编译成功,是因为Animal类中存在move方法,所以编译成功,然而运行时,运行的是特定对象的方法,即运行的是Dog类的move方法.而对Dog c而言,编译阶段首先是去Dog中查找bark(),因此能编译成功,同时也能运行成功:但是对于b.bark()而言,首先是去Animal类中寻找bark(),因为找不到,因而编译错误. public

[ZigBee] 12、ZigBee之看门狗定时器——饿了就咬人的GOOD DOG

引言:硬件中的看门狗,不是门卫的意思,而是一只很凶的狗!如果你不按时喂它,它就会让系统重启!这反而是我们想要的功能~ 1.看门狗概述 看门狗定时器(WDT,Watch Dog Timer)是单片机的一个组成部分,它实际上是一个计数器,一般给看门狗一个数字,程序开始运行后看门狗开始倒计数.如果程序运行正常,过一段时间CPU应发出指令让看门狗复位,重新开始倒计数.如果看门狗减到0就认为程序没有正常工作,强制整个系统复位.因此可以用看门狗防止程序在跑飞的时候回不到正常模式. 看门狗可用于受到电气噪音.

ural 1272. Non-Yekaterinburg Subway

1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t

ural 1269. Obscene Words Filter

1269. Obscene Words Filter Time limit: 0.5 secondMemory limit: 8 MB There is a problem to check messages of web-board visitors for the obscene words. Your elder colleagues commit this problem to you. You are to write a program, which check if there i

ural 1218. Episode N-th: The Jedi Tournament

1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Knights to organize a tournament once. To know, accumulates who the largest amount of Force. Brought each Jedi his lightsaber with him to the tourn