POJ 1269 Intersecting Lines 直线交
不知道谁转的计算几何题集里面有这个题...标题还写的是基本线段求交...
结果题都没看就直接敲了个线段交...各种姿势WA一遍以后发现题意根本不是线段交而是直线交...白改了那个模板...
乱发文的同学真是该死...浪费我几个小时的生命...
/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN (int)5e5+5
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define LINF ((1LL)<<50)
#define INF (1<<30)
#define DINF (1e10)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define LLL cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/
struct POINT{
double x,y;
POINT(double _x = , double _y = ):x(_x),y(_y){};
};
bool operator == (POINT a,POINT b){
if(a.x == b.x && a.y == b.y) return true;
return false;
}
struct LINE{
POINT a,b;
double K,B;
LINE(POINT _a = ,POINT _b = ):a(_a),b(_b){
if((a.x - b.x) == ){
K = DINF;
B = a.x;
}else{
K = ((a.y - b.y) / (a.x - b.x));
B = (- (b.x * a.y - a.x * b.y) / (a.x - b.x));
}
} };
double dist(POINT p1,POINT p2){
return(sqrt((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y)));
}
double multiply(POINT sp,POINT ep,POINT op){
return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y);
}
bool cross_Judge(LINE a ,LINE b) {
double x = multiply(a.a,a.b,b.a);
double y = multiply(a.a,a.b,b.b);
if(x == && y != ) return true;
if(x != && y == ) return true;
return (x * y < );
}
bool same(LINE a , LINE b) {
if(a.a == b.a && a.b == b.b) return true;
if(a.b == b.a && a.a == b.b) return true;
return false;
}
bool onseg(POINT a,POINT s,POINT e){
if(multiply(a,s,e) == && a.x <= max(s.x,e.x) && a.x >= min(s.x,e.x)
&& a.y <= max(s.y,e.y) && a.y >= min(s.y,e.y))
return true;
return false;
}
bool cover(LINE a , LINE b) {
if(multiply(a.a,a.b,b.a) == && multiply(a.a,a.b,b.b) == ){
if(onseg(a.a,b.a,b.b) || onseg(a.b,b.a,b.b)) return true;
if(onseg(b.a,a.a,a.b) || onseg(b.b,a.a,a.b)) return true;
}else return false;
}
bool cross(LINE a , LINE b){
if(min(a.a.x,a.b.x) > max(b.a.x,b.b.x)) return false;
if(min(b.a.x,b.b.x) > max(a.a.x,a.b.x)) return false;
if(min(a.a.y,a.b.y) > max(b.a.y,b.b.y)) return false;
if(min(b.a.y,b.b.y) > max(a.a.y,a.b.y)) return false;
return (cross_Judge(a,b) && cross_Judge(b,a));
}
int main()
{
//FIN;
int n ;
cin>>n;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
for(int i = ; i < n ; i++){
double a,b,c,d,e,f,g,h;
cin>>a>>b>>c>>d>>e>>f>>g>>h;
LINE x = LINE(POINT(a,b),POINT(c,d));
LINE y = LINE(POINT(e,f),POINT(g,h));
if(multiply(x.a,x.b,y.a) == && multiply(x.a,x.b,y.b) == ){
cout<<"LINE"<<endl;
continue;
}else if(x.K == y.K && x.B != y.B){
cout<<"NONE"<<endl;
continue;
}else{
cout<<"POINT ";
if(x.K == DINF){
printf("%.2lf %.2lf\n",x.B,x.B * y.K + y.B);
}else if(y.K == DINF) {
printf("%.2lf %.2lf\n",y.B,y.B * x.K + x.B);
}else {
double cx = (x.B-y.B) / (y.K-x.K);
double cy = x.K * cx + x.B;
printf("%.2lf %.2lf\n",cx,cy);
}
continue;
}
}
cout<<"END OF OUTPUT"<<endl;
return ;
}
POJ 1269 Intersecting Lines 直线交的更多相关文章
- POJ 1269 - Intersecting Lines 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- poj 1269 Intersecting Lines(直线相交)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 391 ...
- 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 (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- 判断两条直线的位置关系 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【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
随机推荐
- windows, fast-rcnn CPU版本的安装配置
一:安装准备 1:caffe的安装配置,本人用的是happynear大神的caffe版本,具体链接https://github.com/happynear/caffe-windows,编译时需要用到p ...
- core组件进阶
访问图像像素 存储方式 BGR连续存储有助于提升图像扫描速度. isContinuous()判断是否是连续存储. 颜色空间缩减 仅用这些颜色中具有代表性的很小的部分,就足以达到同样的效果. 将现有颜色 ...
- js实现观察者模式风格替换
如下图,我们看到两种风格:在选择男士时,页面颜色为黑色:在选择女士时,页面颜色为粉红色. 主要可以分为两类: 下拉框 ---> 被观察者 div ---> 观察者 面向过程实现风格替换: ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- 【Henu ACM Round#19 C】 Developing Skills
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 优先把不是10的倍数的变成10的倍数. (优先%10比较大的数字增加 如果k还有剩余. 剩下的数字都是10的倍数了. 那么先加哪一个 ...
- 以Append方式打开文件,设置偏移量无效
#include<stdio.h> int main() { FILE * fd = fopen("btoo1.c", "ab+"); fpos_t ...
- Map和Collection详解
Collection -----List -----LinkedList 非同步 ----ArrayList 非同 ...
- [Recompose] Handle React Events as Streams with RxJS and Recompose
Events are the beginning of most every stream. Recompose provides a createEventHandler function to h ...
- URAL 1823. Ideal Gas(数学啊 )
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time limit: 0.5 second Me ...
- 10010序列检测器的三段式状态机实现(verilog)
序列检测器是时序数字电路设计中经典的教学范例,夏宇闻的<verilog数字系统设计教程>一书中有这个例子,用verilog设计一个“10010”序列的检测器.看完后我觉得F和G两个状态多余 ...