http://poj.org/problem?id=1269

我会说这种水题我手推公式+码代码用了1.5h?

还好新的一年里1A了~~~~

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const double eps=1e-6;
struct Pt { double x, y; Pt(double _x=0, double _y=0) : x(_x), y(_y) {} };
int dcmp(double a) { if(abs(a)<eps) return 0; return a<0?-1:1; }
typedef Pt Vt;
Vt operator+ (const Pt &a, const Pt &b) { return Vt(a.x+b.x, a.y+b.y); }
Vt operator- (const Pt &a, const Pt &b) { return Vt(a.x-b.x, a.y-b.y); }
Vt operator* (const Pt &a, const double &b) { return Vt(a.x*b, a.y*b); }
bool operator== (const Pt &a, const Pt &b) { return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0; }
double Cross(Vt a, Vt b) { return a.x*b.y-b.x*a.y; } struct Line {
Pt p; Vt v;
Line() {}
Line(Pt &a, Pt &b) { p=a; v=b-a; }
}; Pt getLLP(Line &a, Line &b) {
static Pt p, q;
static Vt u, w, v;
p=a.p; q=b.p;
v=a.v; w=b.v;
u=p-q;
double t1=Cross(w, u)/Cross(v, w);
return p+v*t1;
}
// -1:xiangjiao 0:chonghe 1:pingxing
int LineAndLine(Line &p, Line &q) {
if(dcmp(Cross(p.v, q.v))!=0) return -1;
return dcmp(Cross(q.p-p.p, q.v))==0 && dcmp(Cross(q.p-p.p, p.v))==0;
}
int main() {
int n;
while(~scanf("%d", &n)) {
puts("INTERSECTING LINES OUTPUT");
Line l[2]; Pt p[4];
while(n--) {
rep(k, 4) scanf("%lf%lf", &p[k].x, &p[k].y);
l[0]=Line(p[0], p[1]);
l[1]=Line(p[2], p[3]);
int c=LineAndLine(l[0], l[1]);
if(c==-1) { Pt pt=getLLP(l[0], l[1]); printf("POINT %.2f %.2f\n", pt.x, pt.y); }
else if(c==0) puts("NONE");
else puts("LINE");
}
puts("END OF OUTPUT");
}
return 0;
}

  


Description

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. 
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. 

Input

The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).

Output

There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".

Sample Input

5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5

Sample Output

INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT

Source

【POJ】1269 Intersecting Lines(计算几何基础)的更多相关文章

  1. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  2. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  3. poj 1269 Intersecting Lines

    题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...

  4. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  5. ●POJ 1269 Intersecting Lines

    题链: http://poj.org/problem?id=1269 题解: 计算几何,直线交点 模板题,试了一下直线的向量参数方程求交点的方法. (方法详见<算法竞赛入门经典——训练指南> ...

  6. POJ 1269 - Intersecting Lines - [平面几何模板题]

    题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...

  7. POJ 1269 Intersecting Lines (判断直线位置关系)

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  8. POJ 1269 Intersecting Lines(几何)

    题目链接 题意 : 给你两条线段的起点和终点,一共四个点,让你求交点坐标,如果这四个点是共线的,输出“LINE”,如果是平行的就输出“NONE”. 思路 : 照着ZN留下的模板果然好用,直接套上模板了 ...

  9. POJ 1269 Intersecting Lines(线段相交,水题)

    id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...

  10. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

随机推荐

  1. php中global与$GLOBALS的用法及区别

    php中global 与 $GLOBALS[""] 差别 原本觉得global和$GLOBALS除了写法不一样觉得,其他都一样,可是在实际利用中发现2者的差别还是很大的! 先看下面 ...

  2. java 实现二分查找法

    /** * 二分查找又称折半查找,它是一种效率较高的查找方法. [二分查找要求]:1.必须采用顺序存储结构 2.必须按关键字大小有序排列. * @author Administrator * */ p ...

  3. 转centos65安装简测mysql cluster 7.3.7

    MySQLCluster是sharednothing分布式架构,ndb存储引擎把数据放置于内存中.可以做到无单点故障.由运行于不同服务器上的的多种进程构成,组件包括SQL节点,NDBD数据节点,管理程 ...

  4. Linux卸载系统自带的JDK

    安装Linux后,一般系统都会自带openjdk,我们开发中都需要自己安装,所以需要卸载之前的,以CentOS为例,卸载方法如下: 首先执行命令查看存在哪些已安装的包 rpm -qa | grep j ...

  5. Linux下配置JDK

    下面以CentOS为例,详细说一下Linux下配置JDK的过程 首先按照约定俗成的习惯,将jdk放在/usr/local/java下,首先进入/usr/local然后新建一个目录java 然后我们需要 ...

  6. codeforces 489A.SwapSort 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...

  7. discuz插件开发新手入门 超详细

    作为一个新手,目前也是刚刚玩转discuz的插件功能,好东西不敢独享,就拿出来大家一起分享入门的过程.现在网上很多关于discuz的插件教程都是很简单的教程,原因可能是这个东西是商业化的东西,本着分享 ...

  8. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  9. CityGML文件格式

    1 LOD3中,wall是由cuboid组成的,一个墙面包括8个面,分为wall-1, wall-2...wall-8,door也是,因此他们都是multisurface (一般由8个面片组成). 在 ...

  10. Sublime Text 3 破解+ 汉化包

    破解: 第一步:打开主文件搜索十六进制F7D81AC02005 修改1AC0为B001 第二步:搜索 F3FF8BC7E895 修改其中的8BC7为33C0 第三步:过阻拦未注册提示 搜索 0F859 ...