码迷,mamicode.com
首页 > 其他好文 > 详细

nyoj-1099-Lan Xiang's Square(几何,水题)

时间:2018-04-26 12:29:00      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:while   ++   ble   algo   target   i++   script   pid   tin   

题目链接

 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(几何,水题)

标签:while   ++   ble   algo   target   i++   script   pid   tin   

原文地址:https://www.cnblogs.com/evidd/p/8949784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!