CGL_1_A
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
なかなか忙しい(大嘘)のでとりあえずなかなか手を出していない幾何問題を
これ実装するだけで相当疲れているあたり重症なので早急に問題を解いておきたい
#include <iostream> #include <deque> #include <vector> #include <cstdio> #include <cstring> #include <utility> #include <algorithm> #include <string> #include <cmath> #include <queue> #include <iomanip> #define i64 long long #define ui64 unsigned long long #define REP(i,n) for(int (i)=0;(i)<(n);i++) #define REP2(i,k,n) for(int (i)=(k);(i)<(n);i++) #define MDIST(a,b) abs(a-b) #define DIST(a,b) sqrt((a)*(a)+(b)*(b)) using namespace std; //////////////////////// struct po{ double x,y; po(double x_,double y_):x(x_),y(y_){}; po():x(0),y(0){}; }; struct vc{ double x,y; vc():x(0),y(0){}; vc(po f ,po t):x(t.x - f.x),y(t.y - f.y){ // x = t.x - f.x; // y = t.y - f.y }; }; double norm(vc &a){ return DIST(a.x,a.y); } double dot(vc &a,vc &b){ return a.x*b.x+a.y*b.y; } int main(){ double a,b,c,d; cin >> a >> b >> c >> d; po p(a,b),q(c,d); vc v1(p,q); cin >> a; cout << fixed; cout << setprecision(10); REP(i,a){ cin >> b >> c; po r(b,c); vc v2(p,r); double t = dot(v1,v2) / (norm(v1) * norm(v1)); cout << p.x+v1.x*t << " " << p.y+v1.y*t << endl; } }