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 ...
随机推荐
- hdu1864/2844/2159 背包基础题
hdu1864 01背包 题目链接 题目大意:一堆数,找到一个最大的和满足这个和不超过Q要学会分析复杂度! #include <cstdio> #include <cstring&g ...
- Windows下安装Scrapy方法及常见安装问题总结——Scrapy安装教程
这几天,很多朋友在群里问Scrapy安装的问题,其实问题方面都差不多,今天小编给大家整理一下Scrapy的安装教程,希望日后其他的小伙伴在安装的时候不再六神无主,具体的教程如下. Scrapy是Pyt ...
- bzoj1604 牛的邻居 STL
Description 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l ...
- ifsta---统计网络接口活动状态
ifstat命令就像iostat/vmstat描述其它的系统状况一样,是一个统计网络接口活动状态的工具.ifstat工具系统中并不默认安装,需要自己下载源码包,重新编译安装,使用过程相对比较简单. 下 ...
- 【Henu ACM Round#17 F】Upgrading Array
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果我们对某一个位置i操作两次的话. 显然结果就和操作一次一样. 因为第一次操作过后1..i这些数字就变成是互质的了. gcd为1. ...
- 【Educational Codeforces Round 37 F】SUM and REPLACE
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...
- CSU 1249 竞争性酶抑制剂和同工酶
1249: 竞争性酶抑制剂和同工酶 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 109 Solved: 49 Description 人体内很多化学 ...
- vmware启动虚拟机报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine is stored is almost full. To continue, free an additional 1.4 GB of disk space.
报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine i ...
- 使用commons-email发邮件
这里我用到了两个包: commons-email-1.3.2.jar mail-1.4.1.jar 如果不加mail.jar,就可能会抛出NoClassDefFoundError异常 之后代码引用ht ...
- svn 的使用(二)
这篇主要介绍下 svn 钩子的使用,svn 的安装以及配置等能够查看svn 的使用(一) 我们能够在svn创建的仓库目录下看到 hooks 目录. 这里面就存放这个各种svn操作同一时候会运行的脚本文 ...