Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef struct{
  5. int x, y;
  6. }Point;
  7.  
  8. bool isSquare(Point p1, Point p2, Point p3, Point p4);
  9. int dist(Point m, Point n);
  10.  
  11. int main(void){
  12. int t;
  13. Point p1, p2, p3, p4;
  14.  
  15. scanf("%d", &t);
  16.  
  17. while(t--){
  18. scanf("%d %d", &p1.x, &p1.y);
  19. scanf("%d %d", &p2.x, &p2.y);
  20. scanf("%d %d", &p3.x, &p3.y);
  21. scanf("%d %d", &p4.x, &p4.y);
  22.  
  23. if(isSquare(p1, p2, p3, p4)){
  24. cout<<"Yes"<<endl;
  25. }else{
  26. cout<<"No"<<endl;
  27. }
  28. }
  29. }
  30.  
  31. bool isSquare(Point p1, Point p2, Point p3, Point p4){
  32. //distance of all four sides
  33. int d1 = dist(p1, p2);
  34. int d2 = dist(p4, p3);
  35. int d3 = dist(p1, p4);
  36. int d4 = dist(p2, p3);
  37. //distance of the diagonals
  38. int dg1 = dist(p1, p3);
  39. int dg2 = dist(p2, p4);
  40.  
  41. //distance cannot be zero or negative
  42. if(d1 <= 0 || d2 <= 0 || d3 <= 0 || d4 <= 0 || dg1 <= 0 || dg2 <= 0)
  43. return false;
  44.  
  45. if(d1 == d2){
  46. if(d3 == d4){
  47. if(dg1 == dg2){
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54.  
  55. int dist(Point m, Point n){
  56. return ( sqrt( pow((n.x - m.x), 2) + pow((n.y - m.y), 2) ) );
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement