我是個對電腦科學有興趣的學生,我會貼上我的學習歷程及生活心情,也請大大們多多指教。 :)

2015年5月26日 星期二

[UVa] 10242 - Fourth Point !!

題目網址: http://goo.gl/9feGXR

題意:
(from luckycat)


解 法: 基礎的幾何題目囉。

TAG: Computational Geometry,

注意:

程式碼:
/**
* 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;
}

沒有留言:

張貼留言

任何意見都樂意傾聽