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服务. 因为实施速度快,工程师社区规模大,开 ...
随机推荐
- linux DRM/KMS 测试工具 modetest、kmscude、igt-gpu-tools (一)
这里整理几个在学习Linux DRM/KMS中用到的几个工具,modetest.kmscude.igt-gpu-tools. 简介: modetest 是由libdrm提供的测试程序,可以查询显示设备 ...
- Gym101612L Little Difference
题目链接:https://vjudge.net/problem/Gym-101612L 知识点: 数学 题目大意: 给一个数 \(n(1 \le n \le 10^{18})\),要求将 \(n\) ...
- vue 配置移动单位转换插件 postcss-px-to-viewport
1.先安装插件 npm install postcss-px-to-viewport --save-dev 2.在文件根目录下添加 postcss.config.js 文件 module.export ...
- Linux的运行等级与目标
在老的 Linux 发行版本中,系统运行分成不同的运行级别(run level),不同的级别所启动的服务搭配有所不同.较新的 Linux 发行版本,比如 CentOS 7+,已经将运行级别替换成另一个 ...
- python大量造数据
# -*- coding: utf-8 -*-# date=2020/1/21import timeimport pymysqlimport pymysql.cursors # 获取一个数据库连接,注 ...
- shell判断语句
1.test命令 也可以用[ ]来表示 返回值为0时为true,返回值为1时为false. 例1:str1=aaa,str2=bbb 1)判断字符串是否为空(省略了-n选项,-n选项是不为空,-z ...
- [优文翻译]001.真正程序员该是什么样的(How To Be A Real Programmer)
01.Real Programmers don't write specs -- users should consider themselves lucky to get any programs ...
- python常见面试题讲解(十)数字颠倒
题目描述 描述: 输入一个整数,将这个整数以字符串的形式逆序输出 程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001 输入描述: 输入一个int整数 输出描述: 将 ...
- Azure AD(三)知识补充-Azure资源的托管标识
一,引言 来个惯例,吹水! 前一周因为考试,还有个人的私事,一下子差点颓废了.想了想,写博客这种的东西还是得坚持,再忙,也要检查.要养成一种习惯,同时这也是自我约束的一种形式.虽然说不能浪费大量时间在 ...
- 基于GTID搭建主从MySQL
目录 基于gtid搭建主从MySQL 一.GTID的使用 二.GTID的简介 三.GTID的构成 四.查看GTID的执行情况 4.1 gtid_executed 4.2 gtid_own 4.3 gt ...