zoukankan      html  css  js  c++  java
  • 简单数论

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=232#problem/B

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. 
    Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. 

    The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).

    5
    0 0 4 4 0 4 4 0
    5 0 7 6 1 0 2 3
    5 0 7 6 3 -6 4 -3
    2 0 2 27 1 5 18 5
    0 3 4 0 1 2 2 5


    INTERSECTING LINES OUTPUT
    POINT 2.00 2.00
    NONE
    LINE
    POINT 2.00 5.00
    POINT 1.07 2.20
    END OF OUTPUT





    #include <stdio.h>
    #include <math.h>
    #define eps 1e-8
    #define zero(x) ((x)>0?(x):(-x)<eps)
    struct node
    {
        double xt;
        double yt;
    }ret;
    int p(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
    {
        return (x1 - x2) *(y3 - y4) ==(x3 - x4) *(y1 - y2);
    }
    double xmult(double x1,double y1,double x2,double y2,double x3,double y3)
    {
        return (x1 - x3)*(y2 - y3) - (x2 -x3) *(y1 - y3);
    }
    
    int dots_inline(double x1,double y1,double x2,double y2,double x3,double y3)
    {
        return !xmult(x1,y1,x2,y2,x3,y3);
    }
    void  point(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
    {
        ret.xt = x1;
        ret.yt = y1;
        double t = ((x1 - x3) *(y3 - y4) - (y1 - y3)*(x3 - x4))/((x1 - x2) * (y3 - y4) -(y1 - y2) *(x3 - x4));
        ret.xt += (x2 - x1) * t;
        ret.yt+= (y2 - y1) * t;
    }
    int main()
    {
        int i;
        double x1,y1,x2,y2,x3,y3,x4,y4;
        int n;
        scanf("%d",&n);
        printf("INTERSECTING LINES OUTPUT
    ");
        for(i = 1;i<=n;i++)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
            if(p(x1,y1,x2,y2,x3,y3,x4,y4))
            {
                if(dots_inline(x1,y1,x2,y2,x3,y3))
                printf("LINE
    ");
                else
                printf("NONE
    ");
            }
            else
            {
                point(x1,y1,x2,y2,x3,y3,x4,y4);
                printf("POINT %.2lf %.2lf
    ",ret.xt,ret.yt);
            }
    
        }
        printf("END OF OUTPUT
    ");
        return 0;
    }

    数学题,根据所给的坐标,判断由两点所确定的直线的关系

  • 相关阅读:
    求两条链表有无交点和第一个交点
    重载自增运算符(前置自增++p和后置自增p++)
    二叉排序树和平衡二叉树
    红黑树
    java学习攻略
    Intellij IDEA / IntelliJ
    ngrinder test
    eclipsejeekeplerSR2win32x86_64 jsonedit plugin
    向叶子文文的.net之路学习(大量的转载)
    微软发布机制(转)从浅入深
  • 原文地址:https://www.cnblogs.com/yangyongqian/p/3911917.html
Copyright © 2011-2022 走看看