題意:
(from luckycat)
解 法: 基礎的幾何題目囉。
TAG: Computational Geometry,
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10242 - Fourth Point !! | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/26 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
#define EPS 1e-7 | |
inline const int dcmp( double x ) | |
{ | |
if( x < -EPS ) return -1; return x > EPS; | |
} | |
struct Point { | |
double x, y; | |
Point( double _x=0, double _y=0 ): | |
x(_x), y(_y) {} | |
static bool getPoint( Point &p ) { | |
return scanf( "%lf%lf", &p.x, &p.y ) == 2; | |
} | |
const Point operator+( const Point &op ) const { | |
return Point( x+op.x, y+op.y ); | |
} | |
const Point operator-( const Point &op ) const { | |
return Point( x-op.x, y-op.y ); | |
} | |
const bool operator==( const Point &op ) const { | |
return (!dcmp(op.x-x)&&!dcmp(op.y-y)); | |
} | |
}; | |
// declarations | |
Point a[2], b[2]; | |
// functions | |
// main function | |
int main( void ) | |
{ | |
// input | |
while( Point::getPoint(a[0]) && | |
Point::getPoint(a[1]) && | |
Point::getPoint(b[0]) && | |
Point::getPoint(b[1]) ) { | |
// solve | |
if( a[0] == b[1] ) | |
swap( b[0], b[1] ); | |
else if( a[1] == b[0] ) | |
swap( a[1], a[0] ); | |
else if( a[1] == b[1] ) { | |
swap( a[0], a[1] ); | |
swap( b[0], b[1] ); | |
} | |
// output | |
printf( "%.3lf %.3lf\n", (a[1]+(b[1]-b[0])).x, (a[1]+(b[1]-b[0])).y ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽