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. LA3942 Remember the Word

    题目链接:https://vjudge.net/problem/UVALive-3942 本篇是刘汝佳<算法竞赛入门经典——训练指南>的读书笔记(复述),详见原书 \(P209\) . 解 ...

  2. Node.js NPM Tutorial

    Node.js NPM Tutorial – How to Get Started with NPM? NPM is the core of any application that is devel ...

  3. [Firefox附加组件]0003.弹出对话框

    Firefox中使用面板(panel)模块来显示弹出对话框,面板的内容通过HTML编写.你可以在面板上运行content script,尽管在面板里的脚本无法直接访问插件代码,但是你可以在面板脚本和插 ...

  4. This的关键字的使用

    this: 1.可以用来修饰属性  方法 构造器 2.this理解为当前对象或当前正在创建的对象. 3.可以在构造器中通过this()形参的方式显示的调用本类中其他重载的指定的构造器 要求: 在构造器 ...

  5. toString()方法的使用

    toString()方法: java.lang.Object类的toString()方法的定义如下: public String toString(){ return getClass().getNa ...

  6. ASP.NET中AJAX的异步加载(Demo演示)

    此次的Demo是一个页面,页面上有两行字,然后后面用AJAX,使用一个下拉框去替换第一行文字 第一个是被替换的网页 <!DOCTYPE html> <html> <hea ...

  7. Java实现 蓝桥杯VIP 算法训练 无权最长链

    试题 算法训练 无权最长链 问题描述 给定一个n节点m边的无圈且连通的图,求直径 输入格式 第一行两个数字n,m 接下来m行每行两个数字x,y,代表x,y之间有一条边 输出格式 要求用户的输出满足的格 ...

  8. Java实现 LeetCode 745 前缀和后缀搜索(使用Hash代替字典树)

    745. 前缀和后缀搜索 给定多个 words,words[i] 的权重为 i . 设计一个类 WordFilter 实现函数WordFilter.f(String prefix, String su ...

  9. Java实现 蓝桥杯 基础练习 数列特征

    基础练习 数列特征 时间限制:1.0s 内存限制:256.0MB 提交此题 锦囊1 锦囊2 问题描述 给出n个数,找出这n个数的最大值,最小值,和. 输入格式 第一行为整数n,表示数的个数. 第二行有 ...

  10. Java实现 蓝桥杯 算法提高 拿糖果

    算法提高 拿糖果 时间限制:1.0s 内存限制:256.0MB 问题描述 妈妈给小B买了N块糖!但是她不允许小B直接吃掉. 假设当前有M块糖,小B每次可以拿P块糖,其中P是M的一个不大于根号下M的质因 ...