J - Intersection
来源poj 1410
You are to write a program that has to decide whether a given line segment intersects a given rectangle.
An example:
line: start point: (4,9)
end point: (11,2)
rectangle: left-top: (1,5)
right-bottom: (7,1)

Figure 1: Line segment does not intersect rectangle
The line is said to intersect the rectangle if the line and the rectangle have at least one point in common. The rectangle consists of four straight lines and the area in between. Although all input values are integer numbers, valid intersection points do not have to lay on the integer grid.
Input
The input consists of n test cases. The first line of the input file contains the number n. Each following line contains one test case of the format:
xstart ystart xend yend xleft ytop xright ybottom
where (xstart, ystart) is the start and (xend, yend) the end point of the line and (xleft, ytop) the top left and (xright, ybottom) the bottom right corner of the rectangle. The eight numbers are separated by a blank. The terms top left and bottom right do not imply any ordering of coordinates.
Output
For each test case in the input file, the output file should contain a line consisting either of the letter "T" if the line segment intersects the rectangle or the letter "F" if the line segment does not intersect the rectangle.
Sample Input
1
4 9 11 2 1 5 7 1
Sample Output
F
很坑,如果相交或者在矩形里面就是T,否者就是F;
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
struct point
{
	int x,y;
};
int direction(point p1,point p2,point p3)//p1是向量起点,p2是终点,p3是判断点,>0则在左边<0在右侧
{
return (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x);
}
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		point a[4],t1,t2;
		int x1,x2,y1,y2;
		sf("%d%d%d%d",&t1.x,&t1.y,&t2.x,&t2.y);
		sf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(x1>x2)
		swap(x1,x2);
		if(y1<y2)
		swap(y1,y2);
		a[0].x=x1;a[0].y=y1;
		a[1].x=x1;a[1].y=y2;
		a[2].x=x2;a[2].y=y2;
		a[3].x=x2;a[3].y=y1;
		if(t1.x>x1&&t2.x>x1&&t1.y<y1&&t2.y<y1&&t1.x<x2&&t2.x<x2&&t1.y>y2&&t2.y>y2)
		pf("T\n");
		else if((t1.x<x1&&t2.x<x1)||(t1.x>x2&&t2.x>x2)||(t1.y>y1&&t2.y>y1)||(t1.y<y2&&t2.y<y2))
		pf("F\n");
		else if((direction(t1,t2,a[0])>0&&direction(t1,t2,a[1])>0&&direction(t1,t2,a[2])>0&&direction(t1,t2,a[3])>0)||(direction(t1,t2,a[0])<0&&direction(t1,t2,a[1])<0&&direction(t1,t2,a[2])<0&&direction(t1,t2,a[3])<0))
		pf("F\n");
		else
		pf("T\n");
	}
	return 0;
}
												
											J - Intersection的更多相关文章
- 【BZOJ 1038】【ZJOI 2008】瞭望塔
		
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 半平面交裸题,求完半平面后在折线段上的每个点竖直向上和半平面上的每个点竖直向下求距离,统计最小 ...
 - Fishnet(暴力POJ 1408)
		
Fishnet Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1911 Accepted: 1227 Descripti ...
 - 用C#实现字符串相似度算法(编辑距离算法 Levenshtein Distance)
		
在搞验证码识别的时候需要比较字符代码的相似度用到"编辑距离算法",关于原理和C#实现做个记录. 据百度百科介绍: 编辑距离,又称Levenshtein距离(也叫做Edit Dist ...
 - pthon/零起点(一、集合)
		
pthon/零起点(一.集合) set( )集合,集合是无序的,集合是可变的,集合是可迭代的 set()强型转成集合数据类型 set()集合本身就是去掉重复的元素 集合更新操作案列: j={1,2,3 ...
 - [猜你喜欢]冠军“yes,boy!”分享,含竞赛源代
		
[猜你喜欢]冠军“yes,boy!”分享,含竞赛源代码 DataCastle运营 发表于 2016-7-20 17:31:52 844 3 5 我是Yes,boy! ,来自东北大学计算 ...
 - java csv list cant not repeat
		
require: /** * before: * file A1.csv {1,2,3,4,5} * file A2.csv {2,3,9,10,11} * file B1.csv {5,12,13, ...
 - Solution of NumberOfDiscIntersections by Codility
		
question:https://codility.com/programmers/lessons/4 this question is seem like line intersections qu ...
 - 几何问题  poj  1408
		
参考博客: 用向量积求线段焦点证明: 首先,我们设 (AD向量 × AC向量) 为 multi(ADC) : 那么 S三角形ADC = multi(ADC)/2 . 由三角形DPD1 与 三角形CPC ...
 - POJ 1408:Fishnet
		
Fishnet Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1921 Accepted: 1234 Descripti ...
 
随机推荐
- Revit选择增强插件易蜀预选择过滤器
			
Revit本身提供的选择过滤器能让我们快速选择到我们需要的图元,而将那些不需要的图元排除在选择集之外,如下图所示,假如我们需要选择全部的风管弯头,那么一种方法,我们可以点选,还有就是框选所有弯头,这样 ...
 - [Mockito] Mock List interface
			
In this post, we are going to see more functionalities in Mockito. Mock a List interface: @Test publ ...
 - 《STL源码剖析》学习之traits编程
			
侯捷老师在<STL源码剖析>中说到:了解traits编程技术,就像获得“芝麻开门”的口诀一样,从此得以一窥STL源码的奥秘.如此一说,其重要性就不言而喻了. 之前已经介绍过迭代器 ...
 - C# 使用NLog记录日志入门操作
			
环境:win7 64位, VS2010 1.首先用VS2010创建命令行工程NLogDemo 2.在程序包管理器控制台中输入:Install-Package NLog -Version 4.4.12 ...
 - s:iterator 标签使用错误记录
			
<s:iterator value="newMarriageMoveList" id='tpNewMarriage' status="number"> ...
 - Socket网络编程--小小网盘程序(4)
			
在这一小节中实现了文件的下载,具体的思路是根据用户的uid和用户提供的文件名filename联合两张表,取得md5唯一标识符,然后操作这个标识符对应的文件发送给客户端. 实现下载的小小网盘程序 cli ...
 - 获取应用程序根目录物理路径(Web and Windows)
			
这两个计划写一个小类库,需要在不同项目下任意调用.该类库需要对磁盘文件进行读写,所以就需要获取程序执行的磁盘路径,就简单的对获取磁盘路径的方法进行研究. 借助搜索引擎,我从网上搜罗来多种方法,都可以直 ...
 - Git关于pull,commit,push的总结
			
以前总是由于自己的自身的原因,对于每一次的git的操作,我都是通过eclipse或者是idea来进行的,但是 我每一次都不是很清楚的关于这些方面的操作,现在我们来进行关于git bash的操作,正是由 ...
 - 【iCore4 双核心板_FPGA】例程一:GPIO输出实验——点亮LED
			
实验现象: 三色LED循环点亮. 核心源代码: module led_ctrl( input clk_25m, input rst_n, output fpga_ledr, output fpga_l ...
 - 【iCore1S 双核心板_FPGA】例程二:GPIO输入实验——识别按键输入
			
实验现象: iCore1s 双核心板上与FPGA相连的三色LED(PCB上标示为FPGA·LED),按键按下红灯点亮,松开按键红灯熄灭. 核心源代码: module KEY( input CLK_12 ...