水题。判断两条直线位置关系。

考虑平行的情况,那么 四边形的面积会相等,重合的话,四边形的面积相等且为0.

除去这两种就一定有交点。

 #include <cstdio>
#include <cmath>
#define db double
using namespace std;
const db eps=1e-;
const db pi = acos(-);
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct point{
db x,y;
point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
point operator * (db k1) const{return (point){x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
};
db dot(point k1,point k2){
return k1.x*k2.x+k1.y*k2.y;
}
db cross(point k1,point k2){
return k1.x*k2.y-k1.y*k2.x;
}
int inmid(db k1,db k2,db k3){return sign(k1-k3)*sign(k2-k3)<=;}
int inmid(point k1,point k2,point k3){//k3在[k1,k2]
return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);
}
point getLL (point k1,point k2,point k3,point k4){//两直线交点
db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3);
return (k1*w2+k2*w1)/(w1+w2);
}
bool onS(point k1,point k2,point q){//q在[k1,k2]
return inmid(k1,k2,q)&&sign(cross(k1-q,k2-k1))==;
}
int checkLL(point k1,point k2,point k3,point k4){//求两条直线是否 (平行||重合)
return cmp(cross(k3-k1,k4-k1),cross(k3-k2,k4-k2))==;
}
struct Line{
point p[];
}; db xl,yl,x2,y2;
int n;
point p[];
int main(){
scanf("%d",&n);
printf("INTERSECTING LINES OUTPUT\n");
while (n--){
for(int i=;i<=;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
if(checkLL(p[],p[],p[],p[])){
if(sign(cross(p[]-p[],p[]-p[]))==){
printf("LINE\n");
} else{
printf("NONE\n");
}
} else{
point tmp = getLL(p[],p[],p[],p[]);
printf("POINT %.2f %.2f\n",tmp.x,tmp.y);
}
}
printf("END OF OUTPUT\n");
}

poj 1269的更多相关文章

  1. POJ 1269 (直线求交)

    Problem Intersecting Lines (POJ 1269) 题目大意 给定两条直线,问两条直线是否重合,是否平行,或求出交点. 解题分析 主要用叉积做,可以避免斜率被0除的情况. 求交 ...

  2. 直线相交 POJ 1269

    // 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...

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

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

  4. poj 1269 线段与线段相交

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13605   Accepted: 60 ...

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

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

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

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

  7. poj 1269 Intersecting Lines

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

  8. poj 1269 水题

    题目链接:http://poj.org/problem?id=1269 #include<cstdio> #include<cstring> #include<cmath ...

  9. ●POJ 1269 Intersecting Lines

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

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

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

随机推荐

  1. Introducing XAML Standard and .NET Standard 2.0

    XAML Standard We are pleased to announce XAML Standard, which is a standards-based effort to unify X ...

  2. Arcmap内容列表刷新

    Arcmap内容列表刷新ILayer pLayer = pFDOGLayer as ILayer;                            if (!pLayer.Visible)    ...

  3. Vue Element使用icon图标(第三方)

    element-ui自带的图标库还是不够全,还是需要需要引入第三方icon,自己在用的时候一直有些问题,参考了些教程,详细地记录补充下 对于我们来说,首选的当然是阿里icon库 教程: 1.打开阿里i ...

  4. 使用Jenkins pipeline流水线构建docker镜像和发布

    新建一个pipeline job 选择Pipeline任务,然后进入配置页面. 对于Pipeline, Definition选择 "Pipeline script from SCM" ...

  5. JSP展示两位小数

    <td class="thCenter"> <fmt:formatNumber type="number" value="${rec ...

  6. 【mysql】GitHub 的 MySQL 高可用性实践分享

    原文出处: shlomi-noach   译文出处:oschina    GitHub 使用 MySQL 作为所有非 git 仓库数据的主要存储, 它的可用性对 GitHub 的访问操作至关重要.Gi ...

  7. 自建k8s集群日志采集到阿里云日志服务

    自建k8s集群 的master 节点安装 logtail 采集工具 wget http://logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.c ...

  8. 【C++】C++中typedef、auto与decltype的作用

    typedef 类型别名(type alias)是一个名字,使用typedef不会真正地创建一种新的数据类型,它只是已经存在数据类型的一个新名称.语法: typedef type name; 其中ty ...

  9. java中random()函数用法介绍

    Random() 创建一个新的随机数生成器.  代码如下 复制代码 Random(long seed) 使用单个 long 种子创建一个新的随机数生成器. 我们可以在构造Random对象的时候指定种子 ...

  10. Java并发之线程转储

    一.java线程转储 java的线程转储可以被定义为JVM中在某一个给定的时刻运行的所有线程的快照.一个线程转储可能包含一个单独的线程或者多个线程.在多线程环境中,比如J2EE应用服务器,将会有许多线 ...