POJ 1269 Intersecting Lines(计算几何)
题意:给定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(计算几何)的更多相关文章
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- ●POJ 1269 Intersecting Lines
题链: http://poj.org/problem?id=1269 题解: 计算几何,直线交点 模板题,试了一下直线的向量参数方程求交点的方法. (方法详见<算法竞赛入门经典——训练指南> ...
- POJ 1269 - Intersecting Lines - [平面几何模板题]
题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...
- 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 ...
- poj 1269 Intersecting Lines
题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
随机推荐
- Oracle学习系列1
两个服务必须启动: OracleOraDb10g*TNListener 和 OracleService*** 使用sqlplusw先进行环境的设置 set linesize 300 ; set pag ...
- Draw a Border around any C# Winform Control
public class MyGroupBox : GroupBox { protected override void OnPaint(PaintEventArgs e) { base.OnPain ...
- VGG-19 和 VGG-16 的 prototxt文件
VGG-19 和 VGG-16 的 prototxt文件 VGG-19 和 VGG-16 的 prototxt文件 VGG-16:prototxt 地址:https://gist.github.co ...
- Lucene 对文档打分的规则整理记录
摘引自:http://www.cnblogs.com/forfuture1978/archive/2010/02/08/1666137.html Lucene的搜索结果默认按相关度排序,这个相关度排序 ...
- 从开发的角度比较 ASP.NET Web 服务与 WCF
Windows Communication Foundation (WCF) 具有一个 ASP.NET 兼容模式选项,用户使用此选项可以对 WCF 应用程序进行编程和配置,使其像 ASP.NET We ...
- centos 安装 pip
下载文件 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate 执行安装 python get-pip.py
- .net 开源 JavaScript 解析引擎
1. Javascript .NET 地址为:http://javascriptdotnet.codeplex.com/ 使用方法: Quick Start This section provides ...
- python sys.argv[]
sys.argv[]是用来获取命令行参数的,是一个由该脚本自身路径和其它输入的参数组成的List.sys.argv[0]表示代码本身文件路径. 这里,当我们执行python using_sys.py ...
- XSS转码 && struts2 property标签的bug
struts2: <s:property value="name" escape="false"/> EL表达式: jsp 2.0中的 ${todo ...
- kettle常见问题解决
开源ETL工具kettle系列之常见问题 摘要:本文主要介绍使用kettle设计一些ETL任务时一些常见问题,这些问题大部分都不在官方FAQ上,你可以在kettle的论坛上找到一些问题的答案 1. J ...