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的更多相关文章

  1. 转自知乎,亲民好酒推荐 分类: fool_tree的笔记本 2014-11-08 17:37 652人阅读 评论(0) 收藏

    这里尽量为大家推荐一些符合大众喜好.业内公认好评."即使你不喜欢,你也会承认它不错"的酒款.而且介绍到的酒款还会有一个共同的特征,就是能让你方便的在网上买到. 大概会分为烈酒,利口 ...

  2. Spring Security LDAP简介

    1.概述 在本快速教程中,我们将学习如何设置Spring Security LDAP. 在我们开始之前,了解一下LDAP是什么? - 它代表轻量级目录访问协议.它是一种开放的,与供应商无关的协议,用于 ...

  3. 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 ...

  4. Beam Search(集束搜索/束搜索)

    找遍百度也没有找到关于Beam Search的详细解释,只有一些比较泛泛的讲解,于是有了这篇博文. 首先给出wiki地址:http://en.wikipedia.org/wiki/Beam_searc ...

  5. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  6. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  7. 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 ...

  8. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

  9. 关于Beam Search

    Wiki定义:In computer science, beam search is a heuristic search algorithm that explores a graph by exp ...

随机推荐

  1. python 获取 mac 地址 的代码

    python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac():     if os.name ==  ...

  2. MemProof教程

    简介 MemProof(内存清道夫)是AutomatedQA出品的一款非常不错的检测内存泄漏和资源泄漏的免费调试工具,适合于WIN32平台下使用DELPHI/C++ BUILDER开发的应用程序. 利 ...

  3. 防DDOS攻击

    /ip firewall filter add chain=forward connection-state=new action=jump jump-target=block-ddos add ch ...

  4. Windows 8.1 (64bit) 下搭建 Scrapy 0.22 环境

    我的Windows 8.1 环境 1.下载安装Python 2.7.6 在Python官方网站中下载Python2.7.6的Windows安装包,根据默认配置安装到C:\Python27目录. 安装完 ...

  5. javascript 数组排序之 sort()

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  6. flex 监听网络连接情况

    NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChange); private ...

  7. 【nodejs】 npm 注意事项

    官网:https://www.npmjs.com/ 1.安装时要切换到nodejs根目录,  否则就会安装到安装时所在的目录 2.要有管理员权限(win),如需指定版本,如npm install ex ...

  8. Async详解之一:流程控制

    为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程控制:简化十种 ...

  9. MAC 升级到10.10(OS X Yosemite)下apache+php的配置问题

    MAC升级到最新系统后 本地测试的站点不能正常运行,其原因是mac系统升级后 他的apache的版本也随之升级了版本 Server version: Apache/2.4.9 (Unix) Serve ...

  10. iOS的影片播放 MediaPlayer 和 AVPlayer(转)

    分类: Iphone2013-01-28 16:19 5230人阅读 评论(0) 收藏 举报 在iOS開發上,如果遇到需要播放影片,如開機動畫…,我們很習慣地會使用MediaPlayer來播放影片,因 ...