【Green公式】Hunter’s Apprentice(判断多边形为顺时针或逆时针)--鞋带公式

2023-11-07

题目描述

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
题意
给出一系列点的坐标 每两个点表示一条线 最后判断所走路线是顺时针还是逆时针 逆时针输出fight 顺时针输出run

这里有一个公式大家需要知道–鞋带公式

这里给出一个化简的公式
在这里插入图片描述
https://blog.csdn.net/u012138730/article/details/79814650

去掉上述计算S中的绝对值,让其有正负,判断逆顺:
点序为顺, 面积为负值。
点序为逆,面积为正值。

bool solve(){
    //这里有一个约定,当下标大于n的时候X(n+1)=X1,Y(n+1)=Y1
    for(int i=1;i<n;i++){
        if(i==n) num[i+1].y=num[1].y,num[i+1].x=num[1].x;
        ans+=-0.5*(num[i+1].y+num[i].y)*(num[i+1].x-num[i].x);//由于推导公式得到需要加一个负号
    }
    if(ans<0) return true;//小于0就是顺时针,这个可以通过维基百科加以理解
    return false;
}

https://blog.csdn.net/qq_37602930/article/details/80496498
这样有的博客说是格林公式的特殊情况,emmm,以后再去研究
下面是AC的代码

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int N = 1e6+10;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int MOD=1e9+7;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Abs(x) ((x)>=0?(x):-(x))
int n;
double ans;
struct node{
    double x,y;
}num[100];
bool solve(){
    //这里有一个约定,当下标大于n的时候X(n+1)=X1,Y(n+1)=Y1
    for(int i=1;i<n;i++){
        if(i==n) num[i+1].y=num[1].y,num[i+1].x=num[1].x;
        ans+=-0.5*(num[i+1].y+num[i].y)*(num[i+1].x-num[i].x);//由于推导公式得到需要加一个负号
    }
    if(ans<0) return true;//小于0就是顺时针,这个可以通过维基百科加以理解
    return false;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
    int t;
    scanf("%d",&t);
    while(t--){
        ans=0.0;
        scanf("%d",&n);
        rep(i,1,n) scanf("%lf%lf",&num[i].x,&num[i].y);
        if(solve()) printf("run\n");
        else printf("fight\n");
    }
    return 0;
 }

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【Green公式】Hunter’s Apprentice(判断多边形为顺时针或逆时针)--鞋带公式 的相关文章

  • ChatGPT的接口在哪

    ChatGPT本身不是一个独立的接口 而是一个预训练的自然语言处理模型 如果您需要使用ChatGPT来实现某个自然语言处理任务 例如文本生成 问答等 您可以使用Python中的深度学习框架 如TensorFlow PyTorch 加载预训练

随机推荐

  • 谈我对于ajax的理解

    Ajax的全称是Asynchronous JavaScript and XML 中文名称定义为异步的JavaScript和XML Ajax是Web2 0技术的核心由多种技术集合而成 使用Ajax技术不必刷新整个页面 只需对页面的局部进行更新
  • qt 信号槽默认参数 toggled 和 trigger的区别

    toggled和trigger区别 1 toggle 类似开关 具有2个状态 打开 关闭 使用这个信号 是在这2个状态之间切换 2 trigger是一次性的 点击后 无法改变状态 要么是打开 要么是关闭 参考 http blog csdn
  • c# 对txt文件的读取与写入

    C txt文件分析 读取与写入 c 中对txt文件的读取写入在工作中用到的很多 今天写一个之前工作中用到的小demo 案例场景要求 txt文件中为很多条标记时间戳的报文 需要计算出每条报文从开始接收到结束用了多长时间 案例执行 如txt文件
  • Java数据结构和算法(一)——简介

    本系列博客我们将学习数据结构和算法 为什么要学习数据结构和算法 这里我举个简单的例子 编程好比是一辆汽车 而数据结构和算法是汽车内部的变速箱 一个开车的人不懂变速箱的原理也是能开车的 同理一个不懂数据结构和算法的人也能编程 但是如果一个开车
  • apk文件 -- 反编译

    源博客 https www cnblogs com mfrbuaa p 4588057 html 编译工具 apktool 资源文件获取 能够提取出图片文件和布局文件进行使用查看 dex2jar 将apk反编译成java源代码 classe
  • Python中多线程和线程池的使用方法

    Python是一种高级编程语言 它在众多编程语言中 拥有极高的人气和使用率 Python中的多线程和线程池是其强大的功能之一 可以让我们更加高效地利用CPU资源 提高程序的运行速度 本篇博客将介绍Python中多线程和线程池的使用方法 并提
  • ad9361收发异常问题分析

    最近在调试ad9361 发送都调试好了 但是接收一直没调试好 折腾了一个多月才搞定接收 根据官方提供的api代码 需要修改的有 1 修改reference clk rate参考时钟 2 修改xo disable use ext refclk
  • CTF——被改错的密码

    http ctf idf cn index php g game m article a index id 29 cca9cc444e64c8116a30la00559c042b4看着像一串MD5加密 但是实际不是 去掉中间的l 进行md5
  • 新手小白一看就懂的Excel技能之入门基础

    很多同学开开心心拿到新买的电脑 开机一看 桌面干干净净的 想打开Excel 半天找不到 这些痛 只有新手小白才能懂 今天 我给大家好好讲讲怎么使用Excel 鼠标左键点击电脑桌面左下角的 搜索 输入 Excel 看到 Microsoft O
  • 过拟合现象,原因,以及降低过拟合的方法

    一 什么是过拟合 为什么要避免过拟合 图1 1 Overfit Normal 上图是一张使用线性回归拟合二维样本数据的matlab输出图片 其中Normal曲线是使用使用了带参数空间限制的最小二乘法进行求解的模型 Overfit曲线是使用最
  • 微服务中常用的注解

    注解的定义 Annotation 注解 用于为Java代码提供元数据 简单理解注解可以看做是一个个标签 用来标记代码 是一种应用于类 方法 参数 变量 构造器及包的一种特殊修饰符 1 Target 表示该注解类型所使用的程序元素类型 结合E
  • 机器学习实践(一)—sklearn之概述

    1956年 人工智能元年 人类能够创造出人类还未知的东西 这未知的东西人类能够保证它不误入歧途吗 一 机器学习和人工智能 深度学习的关系 机器学习是人工智能的一个实现途径 深度学习是机器学习的一个方法发展而来 二 机器学习 深度学习的应用场
  • Office 2019 for Mac 安装

    1 下载微软官方Office 2019 for Mac 64位 大小 1 7G 2 按照提示安装Office 2019 for Mac 3 下载14743217 Microsoft Office 2019 VL Serializer安装器
  • 发qq邮件被对方服务器拒绝,QQ被对方拉黑了。我发QQ邮件对对方能收到吗?

    QQ被对方拉黑了 我发QQ邮件对对方能收到吗 以下文字资料是由 历史新知网www lishixinzhi com 小编为大家搜集整理后发布的内容 让我们赶快一起来看一下吧 QQ被对方拉黑了 我发QQ邮件对对方能收到吗 拉黑删除能收到的 邮件
  • Scrapy实战案例--抓取股票数据并存入SQL数据库(JS逆向)

    目标网址 http webapi cninfo com cn marketDataZhishu 之前在这篇文章里面对该网站的JS进行了一个逆向的解析 JS逆向解析案例 接下来我们来创建一个Scrapy项目来爬取某潮的数据并保存在数据库中 过
  • 基于LayUI+Servlet的权限管理系统的设计

    权限管理是所有后台系统的都会涉及的一个重要组成部分 主要目的是对不同的人访问资源进行权限的控制 避免因权限控制缺失或操作不当引发的风险问题 如操作错误 隐私数据泄露等问题 本系统基于JSP Servlet JDBC LayUI的技术 在系统
  • WebRTC打开本地摄像头

    本文使用WebRTC的功能 打开电脑上的摄像头 并且把摄像头预览到的图像显示出来 纯网页实现 能支持除IE外的多数浏览器 手机浏览器也可用 本文链接 引入依赖 我们需要引入adapter latest js 这个WebRTC adapter
  • 计算机中模板与母版的区别,ppt中母版模板主题版式之间的区别和联系?

    ppt中母版模板主题版式之间的区别和联系 由会员分享 可在线阅读 更多相关 ppt中母版模板主题版式之间的区别和联系 1页珍藏版 请在人人文库网上搜索 1 模板是现成的样式 包括图片动画等 直接输入内容就可以使用了 母版是自己设计模板的菜单
  • STM32单片机Flash模拟EEPROM

    摘要 STM32单片机都带有ROM和RAM 其中STM32根据自身的ROM Flash 可以分为小容量产品 中容量产品 大容量产品 根据FLASH容量可以分为 小容量 0 32K 中容量 64 128K 大容量 256K以上 包含256K
  • 【Green公式】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