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. Delphi 二次开发 CorelDRAW

    我们首先通过一个简单的程序例子来看一下Delphi对CorelDRAW二次开发有什么样的效果.本程序实现CorelDRAW程序的打开和关闭. 1.1 Delphi与CorelDRAW连接 在程序与Co ...

  2. C# 获得手机归属地功能

    今天通过查资料了解到web的页面抓取功能,应用HttpWebRequest和HttpWebResponse功能,从http://www.showji.com网站中抓取归属地信息 应该说这个方法是从别的 ...

  3. DataTable中如何去除重复的项【转】

    上周在项目中遇到一个问题,就是获取DataTable中某一列的值,因为从数据库中检索数据时,按照2个字段进行分组,而要获得的那一列刚好在分组这两列中,所以该列的值必然有重复,于是就想到了去除重复,有了 ...

  4. epoll分析

      Epoll详解及源码分析 1.什么是epoll epoll是当前在Linux下开发大规模并发网络程序的热门人选,epoll 在Linux2.6内核中正式引入,和select相似,都是I/O多路复用 ...

  5. sql Mirroring

    http://www.codeproject.com/Articles/109236/Mirroring-a-SQL-Server-Database-is-not-as-hard-as http:// ...

  6. 主成分分析(principal components analysis, PCA)——无监督学习

    降维的两种方式: (1)特征选择(feature selection),通过变量选择来缩减维数. (2)特征提取(feature extraction),通过线性或非线性变换(投影)来生成缩减集(复合 ...

  7. 关于 iOS10 更新后 360 云盘 的上传按钮消失的解决方案

    最近出了iOS10,作为iOS开发者,果断更新. 但是更新完后,打开自己的360云盘,发现想向云盘上传东西,但是传不了,加号按钮不见了. 经过我的研究,原因是 下面的自定义tabbar放置加号按钮的方 ...

  8. oracle 判断是否数字 正则表达式法

     SELECT '-100'    FROM dual   WHERE REGEXP_LIKE('-100','(^[+-]?\d{0,}\.?\d{0,}$)'); REGEXP_LIKE 用法: ...

  9. 通过email分享

    MFMailComposeViewController *mailC=[[MFMailComposeViewControlleralloc] init]; if ([MFMailComposeView ...

  10. C++同步串口通信

    问题描述:     C++串口通信,设置同步串口通信 问题解决:     (1)打开串口 注:     使用串口需要添加<Windows.h>头文件,打开串口主要是使用CreateFile ...