 # Help Codeforces

a guest
Jan 20th, 2016
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <cmath>
3. #include <algorithm>
4. #include <climits>
5. #include <iomanip>
6. #define PI 3.14159265358979323846
7. using namespace std;
8. typedef struct{double x,y;} punct; //a point
9. punct P,varf;
10. int N,i;
11. double rez,R,r;
12. double dist(punct A,punct B) //distance between 2 points A and B
13. {
14.     return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));
15. }
16. double intersectie(punct A,punct B,punct M)
17. {
18.     double x=0,y=0,mMO=0,mAB=0;
19.     mAB=(B.y-A.y)/(B.x-A.x); //m from the straight line equation for side
20.     mMO=(A.x-B.x)/(B.y-A.y); //m for the distance from M to AB
21.     x=(mMO*M.x-mAB*A.x+A.y-M.y)/(mMO-mAB);  // after equations solved, that's the x for O(the end of the perpendicular segment)
22.     y=mMO*(x-M.x)+M.y; //y for point O
23.     punct O;//the point O
24.     O.x=x;
25.     O.y=y;
26.     if((A.x<=x&&x<=B.x)||(A.x>=x&&x>=B.x))//if O is on AB
27.         return dist(O,M);
28.     else
29.         return min(dist(M,A),dist(M,B));
30. }
31. int main()
32. {
33.     cin>>N>>P.x>>P.y;
34.     for(i=1;i<=N;i++)
35.     {