POJ 2624 簡單計算幾何

來源:互聯網
上載者:User

第一次用運算子多載,代碼清晰多了。

已知兩邊,求組成平行四邊形的第4點。運用向量相加性質。

有trick,公用點不一定是給出的第二點和第三點,自行判斷。

/************************ *Creater:Sevenster     * *Time:2012.08.01 12:05 * *PID:POJ 2624          * ************************/#include <iostream>using namespace std;class CPoint{public:      double x, y;      CPoint( double a= 0, double b= 0 )      {              this->x=a;              this->y=b;      }};class CVector{public:       double x, y;       CVector( double a= 0, double b= 0 )       {                this->x=a;                this->y=b;       }};CVector operator-( CPoint b, CPoint a ){        return CVector( b.x- a.x, b.y- a.y );}CVector operator+( CVector a, CVector b ){        return CVector( a.x+ b.x, a.y+ b.y );}void putAns( CPoint p, CPoint o, CPoint q ){     CVector A,B,C;     A= p- o;     B= q- o;     C= A+B;     printf( "%.3lf %.3lf\n", o.x+ C.x, o.y+ C.y );}int main(){    CPoint p1,p2,p3,p4;    while( scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y) != EOF )    {           if( p1.x== p3.x && p1.y== p3.y )               putAns( p2,p1,p4 );           else if( p1.x== p4.x && p1.y== p4.y )               putAns( p2,p1,p3 );           else if( p2.x== p3.x && p2.y== p3.y )               putAns( p1,p2,p4 );           else               putAns( p1,p2,p3 );    }    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.