(线段判交的一些注意。。。)nyoj 1016-德莱联盟

1016-德莱联盟

内存限制:64MB 时间限制:1000ms 特判: No
通过数:9 提交数:9 难度:1

题目描述:

欢迎来到德莱联盟。。。。

德莱文。。。

德莱文在逃跑,卡兹克在追。。。。

我们知道德莱文的起点和终点坐标,我们也知道卡兹克的起点和 终点坐标,问:卡兹克有可能和德莱文相遇吗?,并且保证他们走的都是直线。

输入描述:

几组数据,一个整数T表示T组数据
每组数据 8个实数,分别表示德莱文的起点和终点坐标,以及卡兹克的起点和终点坐标

输出描述:

如果可能 输出 Interseetion,否则输出 Not Interseetion

样例输入:

复制

2
-19.74 7.14 22.23 -27.45 -38.79 -5.08 47.51 34.01
-8.61 9.91 -32.47 6.47 -3.81 -16.1 7.82 -6.37

样例输出:

Interseetion
Not Interseetion 参考链接:https://www.cnblogs.com/sytu/articles/3876585.html这个是线段判交问题,其实线段重合符合这个题的要求。同时需要先进行快速排斥实验,先将两条会在同一条直线上的线段并不重合的情况排除,比如(0 0 1 1 2 2 3 3)这个情况。然后进行跨立实验。并不相交和重合的线段排除。C++代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Point{
    double x1,y1,x2,y2;
}point[2];
int cmp(const Point& a,const Point& b){
    double k1 = (a.x2 - a.x1)*(b.y1 - a.y1) - (b.x1 - a.x1)*(a.y2 - a.y1);
    double k2 = (a.x2 - a.x1)*(b.y2 - a.y1) - (b.x2 - a.x1)*(a.y2 - a.y1);
    if(k1 * k2 <= 0){    //k1*k2 == 0是指的是线段重合。
        return true;
    }
    else{
        return false;
    }
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&point[0].x1,&point[0].y1,
                                         &point[0].x2,&point[0].y2,
                                         &point[1].x1,&point[1].y1,
                                         &point[1].x2,&point[1].y2);
        //快速排斥实验。 只要其中一个为真,那两条线段一定不相交。
        if(!(max(point[0].x1,point[0].x2) < min(point[1].x1,point[1].x2) ||
             max(point[0].y1,point[0].y2) < min(point[1].y1,point[1].y2) ||
             max(point[1].x1,point[1].x2) < min(point[0].x1,point[0].x2) ||
             max(point[1].y1,point[1].y2) < min(point[0].y1,point[0].y2))){
            if(cmp(point[0],point[1]) && cmp(point[1],point[0])){
                printf("Interseetion\n");
            }
            else{
                printf("Not Interseetion\n");
            }
        }
        else{
            printf("Not Interseetion\n");
        }

    }
    return 0;
}
 

请使用手机"扫一扫"x

原文地址:https://www.cnblogs.com/Weixu-Liu/p/10599278.html

时间: 2024-08-02 21:53:29

(线段判交的一些注意。。。)nyoj 1016-德莱联盟的相关文章

德莱联盟 计算几何 线段相交

难度:1 描述 欢迎来到德莱联盟.... 德莱文... 德莱文在逃跑,卡兹克在追.... 我们知道德莱文的起点和终点坐标,我们也知道卡兹克的起点和 终点坐标,问:卡兹克有可能和德莱文相遇吗?,并且保证他们走的都是直线. 输入 几组数据,一个整数T表示T组数据每组数据 8个实数,分别表示德莱文的起点和终点坐标,以及卡兹克的起点和终点坐标 输出 如果可能 输出 Interseetion,否则输出 Not Interseetion 样例输入 2 -19.74 7.14 22.23 -27.45 -38

线段判交——poj2826

目前poj似乎数据出了问题,拿以前a的代码交上去也是wa 总体来说,要考虑三种答案0.00的情况 1.线段不相交 2.一根线段水平 3.开口被封闭,即高的那一端把低的那一端完全遮住了 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; typedef double db; const db eps=1e-6; const db p

(计算几何 线段判交) 51nod1264 线段相交

1264 线段相交 给出平面上两条线段的两个端点,判断这两条线段是否相交(有一个公共点或有部分重合认为相交). 如果相交,输出"Yes",否则输出"No". 输入 第1行:一个数T,表示输入的测试数量(1 <= T <= 1000) 第2 - T + 1行:每行8个数,x1,y1,x2,y2,x3,y3,x4,y4.(-10^8 <= xi, yi <= 10^8) (直线1的两个端点为x1,y1 | x2, y2,直线2的两个端点为x3,y

POJ1408-Fishnet(线段求交)

Fishnet Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1788   Accepted: 1144 Description A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previous night he had enc

You can Solve a Geometry Problem too(线段求交)

http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8861    Accepted Submission(s): 4317 Problem Description Many

线段判非严格相交+暴力——poj2653

O(n2)的暴力居然能过.. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 200005 #define db double const db eps=1e-6; int sign(db k){if (k>eps) return 1; else if (k<-eps) return -1; r

判断线段相交 -- 51nod 1264 线段相交

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264 三角形的有向面积:a.x*b.y+b.x*c.y+c.x*a.y - a.x*c.y - c.x*b.y - b.x*a.y; 上面得到的即是以点A,B,C三点组成的三角形面积的两倍. 如果area >0 则点A,B,C呈逆时针排列. 如果area<0  则点A,B,C呈顺时针排列. 如果area=0  则点A,B,C三点共线. 那么判断线段1(两个端点poin

HDU 题目分类

基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196.1197.1201.1202.1205.1219.1234.1235.1236.1248.1

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12