UPC5292 Hunter’s Apprentice(判断N个点是否是顺时针)

Posted Albert_liu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UPC5292 Hunter’s Apprentice(判断N个点是否是顺时针)相关的知识,希望对你有一定的参考价值。

时间限制: 1 Sec  内存限制: 128 MB
提交: 435  解决: 85
[提交] [状态] [命题人:admin]

题目描述

When you were five years old, you watched in horror as a spiked devil murdered your parents. You would have died too, except you were saved by Rose, a passing demon hunter. She ended up adopting you and training you as her apprentice.
Rose’s current quarry is a clock devil which has been wreaking havoc on the otherwise quiet and unassuming town of Innsmouth. It comes out each night to damage goods, deface signs, and kill anyone foolish enough to wander around too late. The clock devil has offed the last demon hunter after it; due to its time-warping powers, it is incredibly agile and fares well in straight-up fights.
The two of you have spent weeks searching through dusty tomes for a way to defeat this evil. Eventually, you stumbled upon a relevant passage. It detailed how a priest managed to ensnare a clock devil by constructing a trap from silver, lavender, pewter, and clockwork. The finished trap contained several pieces, which must be placed one-by-one in the shape of a particular polygon, in counter-clockwise order. The book stated that the counter-clockwise order was important to counter the clock devil’s ability to speed its own time up, and that a clockwise order would only serve to enhance its speed.
It was your responsibility to build and deploy the trap, while Rose prepared for the ensuing fight. You carefully reconstruct each piece as well as you can from the book. Unfortunately, things did not go as planned that night. Before you can finish preparing the trap, the clock devil finds the two of you. Rose tries to fight the devil, but is losing quickly. However, she is buying you the time to finish the trap. You quickly walk around them in the shape of the polygon, placing each piece in the correct position. You hurriedly activate the trap as Rose is knocked out. Just then, you remember the book’s warning. What should you do next?

 

输入

The first line of input contains a single integer T (1 ≤ T ≤ 100), the number of test cases. The first line of each test case contains a single integer n (3 ≤ n ≤ 20), the number of pieces in the trap. Each of the next n lines contains two integers xi and yi (|xi |, |yi | ≤ 100), denoting the x and y coordinates of where the ith piece was placed. It is guaranteed that the polygon is simple; edges only intersect at vertices, exactly two edges meet at each vertex, and all vertices are distinct.

 

输出

For each test case, output a single line containing either fight if the trap was made correctly or run if the trap was made incorrectly.

 

样例输入

2
3
0 0
1 0
0 1
3
0 0
0 1
1 0

样例输出

fight
run

 

提示

In the first case, you went around the polygon in the correct direction, so it is safe to fight the clock devil
and try to save Rose.
In the second case, you messed up, and it is time to start running. Sorry Rose!

 
 
直接用叉乘判方向只适合凸多边形,如果有一个点时凹进去点就不合适了。
对于存在凹点点多边形,用面积判断是否是顺时针
 
#include "bits/stdc++.h"

using namespace std;
struct point {
    int x, y;
} p[100];


int main() {
    int _;
    cin >> _;
    while (_--) {
        int n;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> p[i].x >> p[i].y;
        }
        p[n] = p[0];
        p[n + 1] = p[1];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = ans + p[i].x * p[i + 1].y - p[i + 1].x * p[i].y;
        }
        if (ans > 0) puts("fight");
        else puts("run");
    }
    return 0;
}

 

 
 

以上是关于UPC5292 Hunter’s Apprentice(判断N个点是否是顺时针)的主要内容,如果未能解决你的问题,请参考以下文章

hdu 4568 Hunter 最短路+dp

UPC10806 矩阵快速幂

UPC2018组队训练赛第三场

Contest Hunter CH6201 走廊泼水节 最小生成树 Kruskal

Hunter狩猎者机器人系统开发(技术搭建)丨狩猎者机器人Hunter项目系统开发(现成源码))

python hunter_wolf.py