UVA10250-The Other Two Trees

來源:互聯網
上載者:User

題意:有兩個樹,求兩棵樹連線上是否存在垂線,求垂線兩個端點的左邊。

思路:其實題目的意思,就好比是四個點構成一個正方形,類似的,就是要求其他兩個端點的座標,我用的是向量旋轉,求另外兩點。

            公式就是(xcost - ysint,xsint + ysint),這裡正好t為直角,所以就是旋轉之後的向量是(-y, x)

#include<stdio.h>int main(){double x1, y1, x2, y2;double ax1, ay1, ax2, ay2;while (scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != EOF){if (x1 == x2 && y1 == y2){printf("Impossible.\n");continue;}double n, m;n = (x1 + x2) / 2.0; m = (y1 + y2) / 2.0;ax1 = n - (y1 - m);ay1 = m - (n - x1);ax2 = 2 * n - ax1;ay2 = 2 * m - ay1;printf("%.10lf %.10lf %.10lf %.10lf\n", ax1, ay1, ax2, ay2);}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.