程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVa 10250 - The Other Two Trees

UVa 10250 - The Other Two Trees

編輯:C++入門知識

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 lengthd 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 point ax1, 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)


============

2 思路
這個題其實是已知正方形兩個對角頂點坐標,求其它兩個坐標。覺得不難,但是剛開始 一直想不出怎麼解決,畫了畫圖,又看了看別人的思路才明白,看來小學數學白學了。

一圖勝千言:\
 

 


注意圖中的四個三角形是全等的,對照圖以及代碼中的計算過程很容易明白。

3 代碼、
 

#include <stdio.h>
#include <math.h>

#define EPS 1e-8

int main() {
  double x1,y1,x2,y2;
  double ax1, ay1, ax2, ay2;
  double a, b;

  while (scanf ("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) != EOF) {
    if (fabs(x1-x2)<EPS && fabs(y1-y2)<EPS) {
      printf ("Impossible.\n");
      continue;
    }

    a = (y1-y2+x2-x1)/2;
    b = (y1-y2-x2+x1)/2;

    ax1 = x2 - a;
    ay1 = y2 + b;
    ax2 = x2 + b;
    ay2 = y2 + a;

    printf ("%.10lf %.10lf %.10lf %.10lf\n", ax1, ay1, ax2, ay2);

  }

  return 0;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved