Consider two points, and . We consider the inversion or point reflection, , of point across point to be a rotation of point around .
Given sets of points and , find for each pair of points and print two space-separated integers denoting the respective values of and on a new line.
Example:
Input: px = 0, py = 0, qx = 1, qy = 1
Output: 2 2
Approach
C++
#include <bits/stdc++.h>using namespace std;vector<int> findPoint(int px, int py, int qx, int qy){vector<int> res;int rx = 2 * qx - px;int ry = 2 * qy - py;res.push_back(rx);res.push_back(ry);return res;}int main(){int px = 0, py = 0;int qx = 1, qy = 1;vector<int> result = findPoint(px, py, qx, qy);for (size_t i = 0; i < result.size(); i++){cout << result[i];if (i != result.size() - 1){cout << " ";}}cout << "\n";return 0;}
No comments:
Post a Comment