【数学】Hunter’s Apprentice

在一场与时间赛跑的战斗中,一位由恶魔猎手抚养长大的年轻人必须利用算法知识,正确设置一个由银、薰衣草、铅锡和钟表机械构成的陷阱,以对抗一个能够扭曲时间的钟魔鬼。若陷阱按逆时针方向设置,则可成功困住敌人;反之,若按顺时针方向设置,则将增强敌人的力量。本故事涉及算法、多边形判断和紧急情况下的决策。

题目描述

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_JUDGE
    freopen("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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值