Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】

问题 H: Hunter’s Apprentice

时间限制: 1 Sec  内存限制: 128 MB
提交: 353  解决: 39
[提交] [状态] [命题人: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.

题意:

你要去帮罗斯去打怪兽balabala,然后你得绕着一个多边形跑,逆时针能帮上忙,顺时针会帮倒忙

给你一堆点坐标,然后按点坐标顺序跑,判断是顺时针还是逆时针 

这有个公式,如果知道公式就是简单题了,

如果不知道又像我这种一辈子都不可能手推出来公式的就只能表示 模板+1

关于公式 https://blog.csdn.net/henuyh/article/details/80378818

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;
double x[1050],y[1050];
int main()
{
  int t;
  read(t);
  while(t--)
  {
    int n;
    read(n);
    double temp = 0;
    rep(i, 0, n)
    {
      scanf("%lf%lf", &x[i], &y[i]);
    }
    rep(i,0,n-1)
    {
      temp += -0.5 * (y[i + 1] + y[i]) * (x[i + 1] - x[i]);
    }
    if(temp > 0)
      cout<<"fight"<<endl;
    else
      cout<<"run"<<endl;
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/kl782636177/article/details/89179236