1 /* 2 Name:nyoj-1099-Lan Xiang‘s Square 3 Copyright: 4 Author: 5 Date: 2018/4/26 9:19:19 6 Description: 7 给4个点,判断是否形成正方形 8 double类型的值比较大小,直接判断==0竟然A了,然而小于1e-6竟然WA 9 */ 10 #include <iostream> 11 #include <cstdio> 12 #include <algorithm> 13 using namespace std; 14 struct node { 15 double x, y; 16 }nodes[5]; 17 double length_edge(node a, node b) { 18 return (b.x - a.x)*(b.x - a.x) + (b.y - a.y)*(b.y - a.y); 19 } 20 int main() 21 { 22 // freopen("in.txt", "r", stdin); 23 int t; 24 cin>>t; 25 while (t--) { 26 for (int i=0; i<4; i++) 27 cin>>nodes[i].x>>nodes[i].y; 28 double edge[4]; 29 edge[0] = length_edge(nodes[0], nodes[1]); 30 edge[1] = length_edge(nodes[0], nodes[2]); 31 edge[2] = length_edge(nodes[0], nodes[3]); 32 if (count(edge, edge+3, 0) >0) { 33 cout<<"No"<<endl; 34 continue; 35 } 36 sort(edge, edge+3); 37 // if (edge[0] - edge[2] + edge[1] < 1e-6 && (edge[0] - edge[1]) < 1e-6) { //WA 38 if (edge[0] - edge[2] + edge[1] ==0 && (edge[0] - edge[1]) == 0) { 39 cout<<"Yes"<<endl; 40 } else { 41 cout<<"No"<<endl; 42 } 43 } 44 return 0; 45 }
nyoj-1099-Lan Xiang's Square(几何,水题)
原文地址:https://www.cnblogs.com/evidd/p/8949784.html
时间: 2024-10-03 10:01:47