Hunter’s Apprentice(判断所走路线为顺时针或逆时针)【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, 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公式】的更多相关文章
- Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】
问题 H: Hunter's Apprentice 时间限制: 1 Sec 内存限制: 128 MB 提交: 353 解决: 39 [提交] [状态] [命题人:admin] 题目描述 When ...
- upc组队赛5 Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】
Hunter's Apprentice 题目描述 When you were five years old, you watched in horror as a spiked devil murde ...
- 【ECNU3386】Hunter's Apprentice(多边形有向面积)
点此看题面 大致题意: 按顺序给你一个多边形的全部顶点,让你判断是按顺时针还是逆时针给出的. 多边形有向面积 显然我们知道,叉积可以求出两个向量之间有向面积的两倍. 所以,我们三角剖分,就可以求出四边 ...
- MySql 的SQL执行计划查看,判断是否走索引
在select窗口中,执行以下语句: set profiling =1; -- 打开profile分析工具show variables like '%profil%'; -- 查看是否生效show p ...
- [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)
题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...
- HDU_1072_Nightmare
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目描述:矩阵表示迷宫,0表示墙,1表示路,2表示起点,3表示终点,4表示重置炸弹时间(6秒),你需 ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
- paip.判断字符是否中文与以及判读是否是汉字uapi python java php
paip.判断字符是否中文与以及判读是否是汉字uapi python java php ##判断中文的原理 注意: 中文与汉字CJKV 的区别..日本,韩国,新加坡,古越南等国家也用汉字,但不是中 ...
- 创业型互联网公司应该选择PHP, JavaEE还是.NET技术路线?
通常JavaEE和.NET被定义为构建大型在线系统,因为其支持面向对象设计,异步通讯,MVC等都相对比较完善,而PHP通常用于构建比较轻量的业务,例如SNS服务. 因为实施速度快,工程师社区规模大,开 ...
随机推荐
- Nginx 运维(安装与使用)
Nginx 运维(安装与使用) 普通安装 Windows安装 (1)进入官方下载地址,选择合适版本(nginx/Windows-xxx). (2)解压到本地 (3)启动 下面以 C 盘根目录为例说明下 ...
- [JavaWeb基础] 023.线程安全(二)
上一篇我们讲解了线程安全的问题,那么要解决线程安全的问题,我们就必须用到线程同步,保证线程之间不互相影响而产生脏数据,下面我们来讲讲具体的实现吧. 首先我们看下例子,我们有个Outputter类,用于 ...
- [Firefox附加组件]0003.弹出对话框
Firefox中使用面板(panel)模块来显示弹出对话框,面板的内容通过HTML编写.你可以在面板上运行content script,尽管在面板里的脚本无法直接访问插件代码,但是你可以在面板脚本和插 ...
- CELF算法原理
影响力传播模型中的独立层叠模型(independent cascading model,IC模型),影响力传播过程中,种子的影响力具备子模性(submodularity),即种子的边际影响力增量会呈现 ...
- strlen 老瓶装新酒
前言 - strlen 概述 无意间扫到 glibc strlen.c 中代码, 久久不能忘怀. 在一无所知的编程生涯中又记起点点滴滴: 编程可不是儿戏 ❀, 有些难, 也有些不舍. 随轨迹一同重温, ...
- python调用大漠插件教程03窗口绑定实例
怎样利用注册好的大漠对象来绑定窗口? 直接上代码,根据代码分析 from win32com.client import Dispatch import os from win32gui import ...
- Java的四种权限修饰符
private:仅对本类可见 缺省(不需修饰符):对本包可见 protected:对本包及所有子类可见 public:对所有类可见 修饰符: * 权限修饰符:private,默认的,protected ...
- CE未知数值修改
一样,用植物大战僵尸测试.来搜索修改向日葵生产阳光的CD值. 由于开始并不知道向日葵cd的初始值,所以用CE搜索未知的初始值 返回游戏,每次向日葵晃一下搜索一下减少的值. 锁定修改为0发现成功. 然后 ...
- xxd十六进制编辑器的安装
一.背景:在vi中使用命令:%!xxd无法进行十六进制编辑,为缺少xxd命令所致 二.yum直接安装xxd无法成功[root@ELK ~]# yum install xxd已加载插件:fastestm ...
- ie时间格式NAN-NAN-NAN
js的日期对象可以识别的日期字符串有四种: 1.YYYY-MM-DD 2019-11-11 01:01:012.MM-DD-YYYY 11-11-2019 01:01:013.YYYY/MM/DD 2 ...