zoukankan      html  css  js  c++  java
  • BOJ 1562 Rectangle

    Rectangle
    Accept:11     Submit:14
    Time Limit:1000MS     Memory Limit:65536KB

    Rectangle

     

    Description

     

    Given three vertices of a rectangle on a 2D plane, you're required to determine the coordinate of the fourth vertex.

    Input Format

     

    An integer T(T100) 
    will exist in the first line of input, indicating the number of test cases.

    Each test case consists of three lines, each with a pair of integers (x,y) 
    , which denotes a coordinate of a vertex.

    All the coordinates will be set in range [10000,10000] 
    . Note that the given vertices will exactly form a right angle.

    Output Format

     

    For each test case, output the coordinate of the required vertex.

    Sample Input

     
    2
    0 0
    0 2
    3 0
    -1 1
    0 0
    1 1
     

    Sample Output

     
    3 2
    0 2

    给一个矩形的三个顶点,求第四个
    我的做法是先用向量乘积为0的方法判断出给出的三点中的直角顶点,再由直角顶点和对角线中点确定出第四个顶点

     1 #include<iostream>
     2 
     3 using namespace std;
     4 
     5 typedef struct point
     6 {
     7     long x;
     8     long y;
     9 } POINT;
    10 
    11 typedef struct vector
    12 {
    13     long x;
    14     long y;
    15 } VECTOR;
    16 
    17 POINT f(POINT l,POINT r,POINT m)
    18 {
    19     POINT mid,result;
    20     mid.x=l.x+r.x;
    21     mid.y=l.y+r.y;
    22     result.x=mid.x-m.x;
    23     result.y=mid.y-m.y;
    24     return result;
    25 }
    26 
    27 int main()
    28 {
    29     int t;
    30     POINT a,b,c,d;
    31     VECTOR m,n,p;
    32 
    33     cin>>t;
    34 
    35     while(t--)
    36     {
    37         cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
    38         m.x=a.x-b.x;
    39         m.y=a.y-b.y;
    40         n.x=b.x-c.x;
    41         n.y=b.y-c.y;
    42         p.x=c.x-a.x;
    43         p.y=c.y-a.y;
    44         if(m.x*n.x+m.y*n.y==0)
    45             d=f(a,c,b);
    46         else if(n.x*p.x+n.y*p.y==0)
    47             d=f(a,b,c);
    48         else if(p.x*m.x+p.y*m.y==0)
    49             d=f(b,c,a);
    50         cout<<d.x<<" "<<d.y<<endl;
    51     }
    52 
    53     return 0;
    54 }
    [C++]
  • 相关阅读:
    如何写文件上传下载
    填充表格的模板代码
    ArcGIS Server 分布式注意事项
    在android上导入第三方jar包 报错:Could not find class
    @Override annotation 出错
    签到时间
    分页三条件查询
    上传图片
    分页
    二级联动
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3181351.html
Copyright © 2011-2022 走看看