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!

思路:

给出一系列点的坐标 每两个点表示一条线 最后判断所走路线是顺时针还是逆时针 逆时针输出fight 顺时针输出run

开始想了个错误的思路 主要是通过三点之间的斜率关系判断 但忽略了k=MAX 或者是 k=-MAX 导致错误

可能还有其他的办法做 这是一种:

green公式:https://baike.baidu.com/item/%E6%A0%BC%E6%9E%97%E5%85%AC%E5%BC%8F/4542338(百度)

推导过程:https://blog.csdn.net/qq_37602930/article/details/80496498

c代码如下:

double d=0;
for(int i=0;i<n-1;i++){
d+=-0.5*(edge[i+1].y+edge[i].y)*(edge[i+1].x-edge[i].x);
}
if(d<0){ ///d<0为顺时针
printf("run\n");
}
else{
printf("fight\n");
}
}

AC代码:

#include<stdio.h>
const int MAX=2e2;
const int MAX1=2e5;
struct node{
double x;
double y;
}edge[MAX+5];
int main()
{
int T;
for(scanf("%d",&T);T--;){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&edge[i].x,&edge[i].y);
}
double d=0;
for(int i=0;i<n-1;i++){
d+=-0.5*(edge[i+1].y+edge[i].y)*(edge[i+1].x-edge[i].x);
}
if(d<0){ ///d<0为顺时针
printf("run\n");
}
else{
printf("fight\n");
}
}
return 0;
}

Hunter’s Apprentice(判断所走路线为顺时针或逆时针)【Green公式】的更多相关文章

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

    问题 H: Hunter's Apprentice 时间限制: 1 Sec  内存限制: 128 MB 提交: 353  解决: 39 [提交] [状态] [命题人:admin] 题目描述 When ...

  2. upc组队赛5 Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】

    Hunter's Apprentice 题目描述 When you were five years old, you watched in horror as a spiked devil murde ...

  3. 【ECNU3386】Hunter's Apprentice(多边形有向面积)

    点此看题面 大致题意: 按顺序给你一个多边形的全部顶点,让你判断是按顺时针还是逆时针给出的. 多边形有向面积 显然我们知道,叉积可以求出两个向量之间有向面积的两倍. 所以,我们三角剖分,就可以求出四边 ...

  4. MySql 的SQL执行计划查看,判断是否走索引

    在select窗口中,执行以下语句: set profiling =1; -- 打开profile分析工具show variables like '%profil%'; -- 查看是否生效show p ...

  5. [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)

    题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...

  6. HDU_1072_Nightmare

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目描述:矩阵表示迷宫,0表示墙,1表示路,2表示起点,3表示终点,4表示重置炸弹时间(6秒),你需 ...

  7. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  8. paip.判断字符是否中文与以及判读是否是汉字uapi python java php

    paip.判断字符是否中文与以及判读是否是汉字uapi python java php   ##判断中文的原理 注意: 中文与汉字CJKV 的区别..日本,韩国,新加坡,古越南等国家也用汉字,但不是中 ...

  9. 创业型互联网公司应该选择PHP, JavaEE还是.NET技术路线?

    通常JavaEE和.NET被定义为构建大型在线系统,因为其支持面向对象设计,异步通讯,MVC等都相对比较完善,而PHP通常用于构建比较轻量的业务,例如SNS服务. 因为实施速度快,工程师社区规模大,开 ...

随机推荐

  1. Spring 基于注解的配置 简介

    基于注解的配置 从 Spring 2.5 开始就可以使用注解来配置依赖注入.而不是采用 XML 来描述一个 bean 连线,你可以使用相关类,方法或字段声明的注解,将 bean 配置移动到组件类本身. ...

  2. AVL树的创建--C语言实现

    AVL树是一种自平衡(Self-balancing)二叉查找树(Binary Search Tree),要求任何一个节点的左子树和右子树的高度之差不能超过1. AVL树的插入操作首先会按照普通二叉查找 ...

  3. fastclick从接触到丢弃

    fastclick简介 fastclick是一款为了解决移动端300ms点击延迟而诞生的插件. 在移动端,如果对页面没有做任何处理,点击一个元素,触发的事件流程可简单理解为:touch -> 经 ...

  4. 微软Azure IoT驱动数字化变革线上分享会(6月4号)

    微软Azure IoT驱动数字化变革线上分享会(6月4号)   微软作为全球范围内IoT领域的领军者,以微软智能云Azure为基础和核心,推动包括物联网.机器学习.微服务.人工智能等在内的新技术的发展 ...

  5. Linux部分场景非常有用的命令集1_chattr&ldd&xargs&screen&ssh&磁盘&du

    这里不做详细说明或截图,仅作为记录和简单说明.注:可能只针对某一命令部分功能,不包含整个功能,若要查看全部请自行查阅文档或help 1.chattr 当某一文件或目录,不想被无意修改或删除(即使roo ...

  6. 利用Nginx设置跨域的方式

    1.服务端可控,添加响应头 2.服务端不可控.通过Nginx反向代理 3.服务端不可控.通过Nginx反向代理添加响应头 第一种方法.服务端可控时,可以在服务器端添加响应头(前端+后端解决) 浏览器地 ...

  7. Vim入门教程——转

    简书: https://www.jianshu.com/p/bcbe916f97e1

  8. Cpusets学习

    1. cpusets 1.1 什么是cpusets cpusets基本功能是限制某一组进程只运行在某些cpu和内存节点上,举个简单例子:系统中有4个进程,4个内存节点,4个cpu.利用cpuset可以 ...

  9. Java实现 蓝桥杯VIP 基础练习 完美的代价

    package 蓝桥杯VIP; import java.util.Scanner; public class 完美的代价 { public static int sum = 0; public sta ...

  10. Java实现 LeetCode 11 盛最多水的容器

    11. 盛最多水的容器 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) ...