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 ...
随机推荐
- CMD和AMD的区别
CMD和AMD俩者之间的区别 AMD和CMD最大的区别是对依赖模块的执行时机处理不同 CMD和AMD都是CommonJS延伸而来的,CommonJS是随着node的出现而出现的,它是一个规范,用于定义 ...
- myisam和innodb的qubie
1.Myisam 支持锁表,innoDB 支持行锁. 2.innoDB 和 BDB 支持事务. 3.Myisam 与 innoDB 索引的区别: Myisam 无论是主键索引还是其他索引,索 ...
- python学习---【__all__】
python包中都会有一个__init__.py的模块,这个模块是区分该父文件是一个python包,或是一个文件目录.这个__init__.py可以是空,也可以添加内容,最常见的就是其中的__all_ ...
- Object-C,四则运算计算器
下面是是一个比较复杂的类. 定义一个四则运算计算器Caculator的接口和实现. 在main函数中,让用户输入四则运算表达式,比如a+b,a-b. 最后,在控制台输出结果. 用到的语法:接口.类的定 ...
- CMSIS-RTOS 信号量
信号量Semaphores 和信号类似,信号量也是一种同步多个线程的方式,简单来讲,信号量就是装有一些令牌的容器.当一个线程在执行过程中,就可能遇到一个系统调用来获取信号量令牌,如果这个信号量包含多个 ...
- ECNUOJ 2575 Separate Connections
Separate Connections Time Limit:5000MS Memory Limit:65536KBTotal Submit:421 Accepted:41 Description ...
- 洛谷 P1898 缘分计算
P1898 缘分计算 题目描述 缘分是一个外国人难以理解的中文名词.大致说来,缘分是一种冥冥中将两人(通常是情人)结合的力量.仅管这是种迷信,很多人——特别是女生——喜欢去计算它. 不幸的是,644 ...
- javascript小白学习指南1---0
第二章 变量和作用域 在看第二章时我希望,你能够回想一下前一次所讲的内容 假设有所遗忘 点这里 今天我们来说说 变量和作用域的问题 本章主要内容 基本类型和引用类型 运行环境 垃圾回收( ...
- (2) 我的结果- spec2006中精确的simulation points运行点
spec06中获取simpoints的环境说明: spec的版本号为spec2006v1.0; 使用ref input with runspec; 100millions为周期生成的simpoints ...
- P2617 Dynamic Ranking
题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是多少(1≤k≤ ...