●POJ 1269 Intersecting Lines
题链:
http://poj.org/problem?id=1269
题解:
计算几何,直线交点
模板题,试了一下直线的向量参数方程求交点的方法。
(方法详见《算法竞赛入门经典——训练指南》P257)
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
};
typedef Point Vector;
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
int N;
bool Point_on_Line(Point P,Vector v,Point Q){
return ((Q-P)^v)==0;
}
Point Line_Intersection(Point P,Vector v,Point Q,Vector w){
static Vector u; static double t1;
u=P-Q;
t1=(w^u)/(v^w);
return P+v*t1;
}
int main(){
Vector v,w;
Point P,_P,Q,_Q,D;
scanf("%d",&N);
printf("INTERSECTING LINES OUTPUT\n");
while(N--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&P.x,&P.y,&_P.x,&_P.y,&Q.x,&Q.y,&_Q.x,&_Q.y);
v=_P-P; w=_Q-Q;
if((v^w)==0){//向量共线
if(Point_on_Line(P,v,Q)) printf("LINE");
else printf("NONE");
}
else{
D=Line_Intersection(P,v,Q,w);
printf("POINT %.2lf %.2lf",D.x,D.y);
}
printf("\n");
}
printf("END OF OUTPUT\n");
return 0;
}
●POJ 1269 Intersecting Lines的更多相关文章
- 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 题目大意:给出四个点的坐标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 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...
- 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 ...
- POJ 1269 Intersecting Lines(线段相交,水题)
id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
随机推荐
- 学号:201621123032 《Java程序设计》第9周学习总结(
1:本周学习总结 1.1:以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容 2:书面作业 2.1: List中指定元素的删除(题集题目) 2.1.1:实验总结.并回答:列举至少2种在List ...
- 利用python实现简单随机验证码
#!/usr/bin/env python # -*- coding:utf-8 -*- import random temp ='' for i in range(6): num = random. ...
- 算法题丨Two Sum
描述 Given an array of integers, return indices of the two numbers such that they add up to a specific ...
- Web系统Login拦截器
所需要导入的包类:import org.springframework.web.servlet.HandleInterceptor;(拦截器要继承该类) public class loginInter ...
- 深度爬取之rules
深度爬取之rules CrawlSpider使用rules来决定爬虫的爬取规则,并将匹配后的url请求提交给引擎.所以在正常情况下,CrawlSpider不需要单独手动返回请求了. 在rules中包含 ...
- api-gateway实践(13)新服务网关 - 断路保护/熔断机制
参考链接:SpringCloud的Hystrix(五) Hystrix机制 新需求列表 1.在线测试 根据定义,生成输入界面, 点击测试, 验证参数,发起调用,返回执行结果 2.熔断保护 两个实现类: ...
- leetcode算法:Trim a Binar Search Tree
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that a ...
- IT技术有感
今天看技术文章,spring相关的,某一个点以前每次看一直不理解, 可是不知道为什么隔了1年左右,中间什么都没做,现在却都懂了. 在看懂的那一刻,笼罩在我心上的躁动突然平静了许多,我的心这一年来前所未 ...
- 初学Java Web(4)——Servlet学习总结
经过一段时间的学习,对于Servlet有了新的不一样的见解,在这里做一下总结,将近来学习到的知识总结一下. Servlet 的请求流程 浏览器发出请求:http://localhost:80/xxx1 ...
- spark2.1注册内部函数spark.udf.register("xx", xxx _),运行时抛出异常:Task not serializable
函数代码: class MySparkJob{ def entry(spark:SparkSession):Unit={ def getInnerRsrp(outer_rsrp: Double, we ...