時間限制:
1000ms
單點時限:
1000ms
記憶體限制:
256mb
給出平面上4條線段,判斷這4條線段是否恰好圍成乙個面積大於0的矩形。
輸入第一行是乙個整數t(1<=t<=100),代表測試資料的數量。
每組資料報含4行,每行包含4個整數x1, y1, x2, y2 (0 <= x1, y1, x2, y2 <= 100000);其中(x1, y1), (x2,y2)代表一條線段的兩個端點。
每組資料輸出一行yes或者no,表示輸入的4條線段是否恰好圍成矩形。
樣例輸入
30 0 0 1
1 0 1 1
0 1 1 1
1 0 0 0
0 1 2 3
1 0 3 2
3 2 2 3
1 0 0 1
0 1 1 0
1 0 2 0
2 0 1 1
1 1 0 1
樣例輸出
yesyesno
#include #include #include using namespace std;
struct line ;
int main()
double slope1, slope2, slope3, slope4;
slope1 = (line1.x1 == line1.x2) ? int_max : (double)(line1.y2 - line1.y1) / (line1.x2 - line1.x1);
slope2 = (line2.x1 == line2.x2) ? int_max : (double)(line2.y2 - line2.y1) / (line2.x2 - line2.x1);
slope3 = (line3.x1 == line3.x2) ? int_max : (double)(line3.y2 - line3.y1) / (line3.x2 - line3.x1);
slope4 = (line4.x1 == line4.x2) ? int_max : (double)(line4.y2 - line4.y1) / (line4.x2 - line4.x1);
if (slope1 == slope2)
//垂直
if (((line1.y1 - line1.y2) * (line3.y1 - line3.y2) +
(line1.x1 - line1.x2) * (line3.x1 - line3.x2)) == 0)
else
} ///
else if (slope1 == slope3)
//垂直
if (((line1.y1 - line1.y2) * (line2.y1 - line2.y2) +
(line1.x1 - line1.x2) * (line2.x1 - line2.x2)) == 0)
else
} /
else if(slope1 == slope4)
//垂直
if (((line1.y1 - line1.y2) * (line3.y1 - line3.y2) +
(line1.x1 - line1.x2) * (line3.x1 - line3.x2)) == 0)
else
} /
else
} return 0;
}
hihoCoder 1040 矩形判斷
描述 給出平面上4條線段,判斷這4條線段是否恰好圍成乙個面積大於0的矩形。輸入 輸入第一行是乙個整數t 1 t 100 代表測試資料的數量。每組資料報含4行,每行包含4個整數x1,y1,x2,y2 0 x1,y1,x2,y2 100000 其中 x1,y1 x2,y2 代表一條線段的兩個端點。輸出 ...
hihoCoder1040 矩形判斷
大體思路是可以出來的,就是先判斷能否組成四邊形,然後再判斷能否組成矩形。四邊形這部分比較難搞,但是我們有st l 啊,直接自定義乙個小於號,然後把所有的點扔進se t 最後看下si ze是不是等於 4 就好了。好,我們已經知道了這是乙個四邊形,再怎麼判斷它是否是矩形?思來想去啊,似乎計算幾何中沒有簡...
hihoCoder1040 矩形判斷
時間限制 1000ms 單點時限 1000ms 記憶體限制 256mb 描述給出平面上4條線段,判斷這4條線段是否恰好圍成乙個面積大於0的矩形。輸入輸入第一行是乙個整數t 1 t 100 代表測試資料的數量。每組資料報含4行,每行包含4個整數x1,y1,x2,y2 0 x1,y1,x2,y2 100...