zoukankan      html  css  js  c++  java
  • UVa 10250 The Other Two Trees

    Problem E

    The Other Two Trees

    Input: standard input

    Output: standard output

    Time Limit: 2 seconds

    You have a quadrilateral shaped land whose opposite fences are of equal length. You have four neighbors whose lands are exactly adjacent to your four fences, that means you have a common fence with all of them. For example if you have a fence of length d in one side, this fence of length d is also the fence of the adjacent neighbor on that side. The adjacent neighbors have no fence in common among themselves and their lands also don’t intersect. The main difference between their land and your land is that their lands are all square shaped. All your neighbors have a tree at the center of their lands. Given the Cartesian coordinates of trees of two opposite neighbors, you will have to find the Cartesian coordinates of the other two trees.

    Input

    The input file contains several lines of input. Each line contains four floating point or integer numbers x1, y1, x2, y2, where (x1, y1), (x2, y2) are the coordinates of the trees of two opposite neighbors. Input is terminated by end of file.

    Output

    For each line of input produce one line of output which contains the line “Impossible.” without the quotes, if you cannot determine the coordinates of the other two trees. Otherwise, print four floating point numbers separated by a single space with ten digits after the decimal pointax1, ay1, ax2, ay2, where (ax1, ay1)  and (ax2, ay2) are the coordinates of the other two trees. The output will be checked with special judge program, so don’t worry about the ordering of the points or small precision errors. The sample output will make it clear.

    Sample Input

    10 0 -10 0

    10 0 -10 0

    10 0 -10 0

    Sample Output

    0.0000000000 10.0000000000 0.0000000000 -10.0000000000

    0.0000000000 10.0000000000 -0.0000000000 -10.0000000000

    0.0000000000 -10.0000000000 0.0000000000 10.0000000000


    (World Final Warm-up Contest, Problem Setter: Shahriar Manzoor)

    由题意很容易发现,四棵苹果树构成了一个正方形。

    由给定的两个点,先求出中点,再求出由这两个点确定的向量,将这个向量逆时针旋转90度再除以二,加到中点上去即可求出正方形的另外两个点

    向量(x,y)逆时针旋转90度变为(-y,x)

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     double x1,y1,x2,y2,ax1,ay1,ax2,ay2,mx,my,vx,vy;
    10 
    11     while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)==4)
    12     {
    13         if(x1>=x2)
    14         {
    15             swap(x1,x2);
    16             swap(y1,y2);
    17         }
    18 
    19         mx=(x1+x2)/2;
    20         my=(y1+y2)/2;
    21         vx=(x2-x1)/2;
    22         vy=(y2-y1)/2;
    23 
    24         swap(vx,vy);
    25         vx=-vx;
    26 
    27         ax1=mx+vx;
    28         ay1=my+vy;
    29 
    30         ax2=mx-vx;
    31         ay2=my-vy;
    32 
    33         printf("%.10f %.10f %.10f %.10f
    ",ax1,ay1,ax2,ay2);
    34     }
    35 
    36     return 0;
    37 }
    [C++]
  • 相关阅读:
    (转)[Unity3D]计时器/Timer
    characterCustomezition的资源打包代码分析
    论文笔记:语音情感识别(四)语音特征之声谱图,log梅尔谱,MFCC,deltas
    论文笔记:语音情感识别(三)手工特征+CRNN
    论文笔记:语音情感识别(二)声谱图+CRNN
    论文笔记:2018 PRCV 顶会顶刊墙展
    论文笔记:Emotion Recognition From Speech With Recurrent Neural Networks
    CTC(Connectionist Temporal Classification)介绍
    论文笔记:语音情感识别(一)语音知识概览
    710 Random Pick with Blacklist
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3536724.html
Copyright © 2011-2022 走看看