題目描述
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!
?
題目大意:
先輸入一個整數t,下面有t組測試,對于每組測試,先輸入一個整數n,然后按順序輸入n個點的坐標,這些點能圍成一個多邊形,最后根據若是按順時針轉,則輸出run,否則輸出fight。
解題思路:
這題是要求多邊形的順逆時針的問題,其實就是通過一個模板直接判斷,知道這個模板的話非常簡單,此題可以通過Green公式求解多邊形順逆時針來解。
代碼:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
struct node
{double x,y;
}arr[100];
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int t;cin>>t;while(t--) {int n;cin>>n;rep(i,1,n) cin>>arr[i].x>>arr[i].y;double nape=0;rep(i,1,n-1) {nape+=(-0.5)*(arr[i+1].x-arr[i].x)*(arr[i+1].y+arr[i].y); //Green公式}nape+=(-0.5)*(arr[1].x-arr[n].x)*(arr[1].y+arr[n].y);if(nape<0) cout<<"run"<<endl;else cout<<"fight"<<endl;}return 0;
}
?