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;
    }

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

  • 相关阅读:
    jQuery中$.each()方法的使用
    点击分享功能
    localStorage使用总结
    核桃说笔记2
    php 微信模板消息发送
    报错:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
    报错:Cannot remove entries from nonexistent file c:program filesanaconda3libsite-packageseasy-install.pth
    Pycharm如何修改背景图(BackgroundColor)
    git 设置 .gitignore 为全局global + 配置.gitignore为全局后不生效解决办法
    Windows Server 2016 下执行定时任务(英文系统)
  • 原文地址:https://www.cnblogs.com/yangyongqian/p/3911917.html
Copyright © 2011-2022 走看看