## UVA 10242 - Fourth Point!! ### 題意: ###### 每一行輸入共有 8 個小數,依序代表四個點的 (x,y)。但其中有一點會出現兩次,因此實際上只給了三個不同的點 A、B、C,另外一個點是重複的 D(D = A 或 B 或 C)。這三個不同的點是平行四邊形的三個頂點,題目要你把第四個頂點算出來並列印。 ###### (這裡只是我想發牢騷) : 這題是我CPE49題裡面最晚寫的一題,也是我覺得最難的一題,因為這題目敘述真的是#@!#$^%^&(真的超想罵但是...好,我嘴巴閉閉 : ) ) ### Sample Input: ###### 每行為一個test case,輸入直到EOF,每個test case裡面有8個浮點數,代表平行四邊形的三個點座標(其中有一個點是重複的)。 ###### ==重複的點和其他兩個點的連線為平行四邊形的兩個邊。==(重複點為所求點的對角) ```= 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 ``` ### 程式碼: ```cpp= #include <iostream> #include <vector> #define haku author using namespace std; struct Point{ float x, y; }; int main(){ Point p; vector<float> x(4), y(4); while(cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) { vector<Point> rec(4); for (int i = 0; i < 4; i++) { p.x = x[i]; p.y = y[i]; rec[i] = p; } int dup; // 找出複製點座標 for (int i = 1; i < 4; i++) { for (int j = i - 1; j >= 0; j--) { if (rec[i].x == rec[j].x && rec[i].y == rec[j].y) dup = i; } } // 第四個點座標 = 複製點座標 + (兩邊向量和) float x = rec[dup].x, y = rec[dup].y; for (int i = 0; i < 4; i++) { if (i != dup) { x += (rec[i].x - rec[dup].x); y += (rec[i].y - rec[dup].y); } } printf("%.3f %.3f\n", x, y); } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up