Problem Description
source:https://uva.onlinejudge.org/external/102/10242.html
Given are the (x, y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the (x, y) coordinates of the fourth point.
Input
Each line of input contains eight floating point numbers: the (x, y) coordinates of one of the endpoints of the first side followed by the (x, y) coordinates of the other endpoint of the first side, followed by the (x, y) coordinates of one of the endpoints of the second side followed by the (x, y) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between −10000 and +10000. Input is terminated by end of file.
Output
For each line of input, print the (x, y) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.
Sample Input
0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145
Sample Output
1.000 0.000
-2.500 -2.500
0.151 -0.398
Solution:
source:https://uva.onlinejudge.org/external/102/10242.html
Given are the (x, y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the (x, y) coordinates of the fourth point.
Input
Each line of input contains eight floating point numbers: the (x, y) coordinates of one of the endpoints of the first side followed by the (x, y) coordinates of the other endpoint of the first side, followed by the (x, y) coordinates of one of the endpoints of the second side followed by the (x, y) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between −10000 and +10000. Input is terminated by end of file.
Output
For each line of input, print the (x, y) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.
Sample Input
0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145
Sample Output
1.000 0.000
-2.500 -2.500
0.151 -0.398
Solution:
#include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include<stdio.h> #include<stdlib.h> using namespace std; int main() { int i,j,x1,x2,x3,y2; double x[5],y[5],a,b,x4,y4; while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2],&x[3],&y[3],&x[4],&y[4])==8) { for(i=1;i<=3;i++) { for(j=i+1;j<=4;j++) { if(x[i]==x[j] && y[i]==y[j]) { x2=i; y2=j; } } } for(i=1;i<=4;i++) { if(i!=x2 && i!=y2) { x1=i; break; } } for(i=1;i<=4;i++) { if(i!=x2 && i!=y2 && i!=x1) { x3=i; break; } } a=(x[x1]+x[x3])/2; b=(y[x1]+y[x3])/2; x4=2*a-x[x2]; y4=2*b-y[x2]; printf("%.3lf %.3lf\n",x4,y4); } return 0; }
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience