题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点。

题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平行,最后就是相交了,求交点就好了。

求交点的过程和高中知识差不多,用y=kx+c来求,只不过要注意斜率不存在的时候特殊处理,还有就是求斜率的时候一定要强制转换,(坑爹的我,调试了一小时才找到这个bug)

AC代码:

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int INF=0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
#define prN printf("\n")
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d%d",&(N),&(M))
#define SIII(N,M,K) scanf("%d%d%d",&(N),&(M),&(K))
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
const int MAX_N= 1 ;
const int EPS= 1e-9 ;
int a[10][8],n; int Multic(int x0,int y0,int x1,int y1,int x2,int y2)
{
int a1=x1-x0,b1=y1-y0;
int a2=x2-x0,b2=y2-y0;
return a1*b2-a2*b1;
} void sol(int row)
{
int te1=Multic(a[row][0],a[row][1],a[row][4],a[row][5],a[row][2],a[row][3]);
int te2=Multic(a[row][0],a[row][1],a[row][6],a[row][7],a[row][2],a[row][3]);
if (te1==0&&te2==0)
{
puts("LINE");
return;
}
if ((a[row][1]-a[row][3])*(a[row][4]-a[row][6])==
(a[row][0]-a[row][2])*(a[row][5]-a[row][7]))
{
puts("NONE");
return;
}
if (a[row][0]-a[row][2]==0||(a[row][4]-a[row][6])==0)
{
if (a[row][0]-a[row][2]==0)
{
double ansx=a[row][0];
double k2=(a[row][5]-a[row][7])/(double)(a[row][4]-a[row][6]);
double c2=a[row][7]-k2*a[row][6];
double ansy=k2*ansx+c2;
printf("POINT %.2f %.2f\n",ansx,ansy);
}
if ((a[row][4]-a[row][6])==0)
{
double ansx=a[row][4];
double k1=(a[row][1]-a[row][3])/(double)(a[row][0]-a[row][2]);
double c1=a[row][1]-k1*a[row][0];
double ansy=k1*ansx+c1;
}
return;
} double k1=(a[row][1]-a[row][3])/(double)(a[row][0]-a[row][2]);///一定要注意这 ,要强制类型转换!!!!!!!!!!!!
double k2=(a[row][5]-a[row][7])/(double)(a[row][4]-a[row][6]);///否则就是int除int了 double c1=a[row][1]-k1*a[row][0];
double c2=a[row][7]-k2*a[row][6]; double ansx=(c2-c1)/(k1-k2);
double ansy=k1*ansx+c1; printf("POINT %.2f %.2f\n",ansx,ansy);
} int main()
{
SI(n);
rep(i,n)
rep(j,8)
SI(a[i][j]);
puts("INTERSECTING LINES OUTPUT");
rep(i,n)
sol(i);
puts("END OF OUTPUT");
return 0;
}

  

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

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

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

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

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

  3. ●POJ 1269 Intersecting Lines

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

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

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

  5. POJ P2318 TOYS与POJ P1269 Intersecting Lines——计算几何入门题两道

    rt,计算几何入门: TOYS Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  6. poj 1269 Intersecting Lines

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

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

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

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

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

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

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

随机推荐

  1. Codeforces Round #123 (Div. 2)

    A. Let's Watch Football 记时间为\(t\), 则\(bt+(b-a)c>=0\),可得\[t \ge \frac{c(a-b)}{b}\] B. After Traini ...

  2. POJ1149 PIGS (网络流)

                                                                             PIGS Time Limit: 1000MS   M ...

  3. Java基础相关

    对老师上课内容进行总结: 1.新建一个Java项目,并命名为HelloWorld 然后再新建类,并命名为HelloWorld,注意红色画圈部分 若勾选,则新建类开头为(“//后的内容为老师所讲批注”) ...

  4. HDU-1255 覆盖的面积 (扫描线)

    题目大意:给若干个矩形,统计重叠次数不为0的面积. 题目分析:维护扫描线的长度时,只需要只统计覆盖次数大于1的区间即可.这是个区间更新,不过不能使用懒标记,但是数据规模不大,不用懒惰标记仍可以AC. ...

  5. 【转】 iOS日常学习 - iOS10上关于NSPhotoLibraryUsageDescription等问题

    原文网址:http://blog.csdn.net/wang631106979/article/details/52578001 最近升级了Xcode8.0,真是很多坑啊,填完一个来另外一个,今天又遇 ...

  6. 【转】iOS10项目打包上传被拒关于隐私权限问题

    原文网址:http://blog.csdn.net/yidu_blog/article/details/53064987 今天项目打包提交.收到了苹果的邮件.主要内容: This app attemp ...

  7. IOCP 浅析

    http://www.ibm.com/developerworks/cn/java/j-lo-iocp/ https://msdn.microsoft.com/en-us/library/window ...

  8. add to svn ignore disabled

    The problem is that the folder is already under version control. Here's how I fix this type of probl ...

  9. shell脚本实例-菜单样例

    1.9.1 实例需求 用户在进行Linux系统管理的过程中,经常需要用到查看进程的信息.用户的信息等常用的功能.本例针对这一需求,使用shell编程实现基本的系统管理 功能.通过本程序,可以按照要求实 ...

  10. Openjudge计算概论-奇数单增序列

    /*===================================== 奇数单增序列 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个长度为N(不大于500)的正整数序列 ...