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 ...
随机推荐
- 程序日志--ios“考反应扑克游戏”程序
交代一下我做程序的工具:mac os x虚拟机10.9.3 Xcode6 百度^-^ 參考书iPhone30天精通 总结与经验,还有遇到的问题,都在程序 ...
- android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)
android ndk-build 编译静态库libxx.a 需求场景: 目前有安卓编码好的现在的openssl的两个.a,我们需要调用openssl的函数,并把功能再封装成.a; 这样使用时,在an ...
- ORA-00959: tablespace 'TB01' does not exist
当前的表空间如下: SQL> select name from v$tablespace; NAME ---------------------------------------------- ...
- pycharm调整代码长度分割线
1.File -> Settings -> Code Style -> Right margin (columns) 的值为80,大功告成. 2.具体设置的数值可以根据个人电脑 ...
- Linux ext3/ext4数据恢复
2012年12月9日 测试环境: Ubuntu 12.04 X86 +ext4 恢复文件使用的工具:extundelete(点击下载) 说明:当文件异常消失或者rm误删除后,避免在该分区中继 ...
- 物联网架构成长之路(17)-SpringCloud目前遇到的注意事项
1. STS插件最好是要安装的. 2. 对应的Decompiler插件也是要安装的. 3. 如果遇到maven工程因为找不到包问题的, 在确认pom.xml 文件没有问题的情况下, 右键项目-Mave ...
- 《深入应用C++11:代码优化与工程级应用》勘误表
<深入应用C++11:代码优化与工程级应用>勘误表,会不断更新,欢迎读者留言或发邮件(cpp11book@163.com)给我提出宝贵意见. 1.第7.3节目录final和override ...
- default listener is not configured in grid infrastructure home
Oracle Restart enable database creation requries Default listener configured and running in Grid Inf ...
- 在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求(转)
通用辅助类 下面是我编写的一个辅助类,在这个类中采用了HttpWebRequest中发送GET/HTTP/HTTPS请求,因为有的时候需要获取认证信息(如Cookie),所以返回的是HttpWebRe ...
- left join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...