*[hackerrank]Jim Beam
https://www.hackerrank.com/contests/infinitum-aug14/challenges/jim-beam
学习了线段相交的判断法。首先是叉乘,叉乘的几何意义是有向的平行四边形的面积(除以2就是三角形的面积)。如果ABD和ABC正负相反,说明C和D在AB两侧,同样的,再判断A和B是否在CD两侧即可。当某三角形面积为0时,需要判断是否在线段上。
#include <iostream>
using namespace std; typedef long long LL;
LL cross_product(LL ax, LL ay, LL bx, LL by, LL cx, LL cy) {
return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
} bool inside(LL ax, LL ay, LL bx, LL by, LL cx, LL cy) {
return (min(ax, bx) <= cx && cx <= max(ax, bx)
&& min(ay, by) <= cy && cy <= max(ay, by));
} bool intersect(LL ax, LL ay, LL bx, LL by, LL cx, LL cy) {
LL abc = cross_product(ax, ay, bx, by, cx, cy);
LL abd = cross_product(ax, ay, bx, by, 0, 0);
LL cda = cross_product(cx, cy, 0, 0, ax, ay);
LL cdb = cross_product(cx, cy, 0, 0, bx, by);
if (((abc > 0 && abd < 0)
|| (abc < 0 && abd > 0))
&& ((cda > 0 && cdb < 0)
|| (cda < 0 && cdb > 0)))
return true;
if (abc == 0 && inside(ax, ay, bx, by, cx, cy)) return true;
if (abd == 0 && inside(ax, ay, bx, by, 0, 0)) return true;
if (cda == 0 && inside(cx, cy, 0, 0, ax, ay)) return true;
if (cdb == 0 && inside(cx, cy, 0, 0, bx, by)) return true; return false;
} void solve() {
int x1, y1, x2, y2, x, y;
cin >> x1 >> y1 >> x2 >> y2 >> x >> y;
if (intersect(x1, y1, x2, y2, x, y))
cout << "NO" << endl;
else
cout << "YES" << endl;
} int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
*[hackerrank]Jim Beam的更多相关文章
- 转自知乎,亲民好酒推荐 分类: fool_tree的笔记本 2014-11-08 17:37 652人阅读 评论(0) 收藏
这里尽量为大家推荐一些符合大众喜好.业内公认好评."即使你不喜欢,你也会承认它不错"的酒款.而且介绍到的酒款还会有一个共同的特征,就是能让你方便的在网上买到. 大概会分为烈酒,利口 ...
- Spring Security LDAP简介
1.概述 在本快速教程中,我们将学习如何设置Spring Security LDAP. 在我们开始之前,了解一下LDAP是什么? - 它代表轻量级目录访问协议.它是一种开放的,与供应商无关的协议,用于 ...
- Beam编程系列之Apache Beam WordCount Examples(MinimalWordCount example、WordCount example、Debugging WordCount example、WindowedWordCount example)(官网的推荐步骤)
不多说,直接上干货! https://beam.apache.org/get-started/wordcount-example/ 来自官网的: The WordCount examples demo ...
- Beam Search(集束搜索/束搜索)
找遍百度也没有找到关于Beam Search的详细解释,只有一些比较泛泛的讲解,于是有了这篇博文. 首先给出wiki地址:http://en.wikipedia.org/wiki/Beam_searc ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- HackerRank "Minimum Penalty Path"
It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- 关于Beam Search
Wiki定义:In computer science, beam search is a heuristic search algorithm that explores a graph by exp ...
随机推荐
- IOS_修改项目模板
1. /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source/Cocoa\ ...
- 自动设置iframe大小的jQuery代码
自动设置iframe的宽度,如何用jquery来实现呢? 代码: <iframe src="main_folder.aspx" class="global_main ...
- impdp ORA-29913: error in executing ODCIEXTTABLEOPEN callout
1.数据导出时的日志 ;;; Export: Release :: Copyright (c) , , Oracle and/or its affiliates. All rights reserve ...
- Ztack学习笔记(1)-初识Ztack
一.Zigbee协议 Zigbee是IEEE 802.15.4协议的代名词,是一种短距离.低功耗的无线通信技术.这一名称来源于蜜蜂的八字舞,因为蜜蜂(bee)是靠飞翔和“嗡嗡”(zig)地抖动翅膀的“ ...
- Ubuntu修改密码长度太短或太简单解决
在安装 Ubuntu 的时候建立的帐户 sai,想把密码改成两个字母aa,方便输入. 运行终端 sai@xmomx:~$ passwd sai更改 sai 的密码.(当前)UNIX 密码: xx输入新 ...
- IIS支持PHP
1. 解压php-5.2.6.zip到D:\php5,找到php.ini-dist改名为php.ini并将它放到C:\WINDOWS目录下. 2. 将D:\ php5目录下的libmcrypt.dll ...
- nginx error_page 404 用 php header 无法跳转
nginx error_page 404 用 php header 无法跳转 之前用Apache的时候,只需要设置 ErrorDocument 404 /404.php 就可以在 404.php 中根 ...
- VBS基础篇 - 循环
经常地,当编写代码时,我们希望将一段代码执行若干次,我们可以在代码中使用循环语句来完成这项工作. 循环可分为三类:一类在条件变为 False 之前重复执行语句,一类在条件变为 True 之前重复执行语 ...
- java NIO与IO的区别
nio是new io的简称,从jdk1.4就被引入了.现在的jdk已经到了1.6了,可以说不是什么新东西了.但其中的一些思想值得我来研究.这两天,我研究了下其中的套接字部分,有一些心得,在此分享. 首 ...
- Java 8 VM GC Tuning Guide Charter3-4
第三章 Generations One strength of the Java SE platform is that it shields the developer from the compl ...