fork(1) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4.  
  5. using namespace std;
  6.  
  7. #define ll long long
  8.  
  9. ll p,x[5],y[5],t;
  10. int i,j,tt;
  11.  
  12. ll sqr(ll x)
  13. {
  14. return x*x;
  15. }
  16.  
  17. long double dist(ll x1, ll y1, ll x2, ll y2)
  18. {
  19. return sqrt(sqr(x1-x2)+sqr(y1-y2));
  20. }
  21.  
  22. long double getcos(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4)
  23. {
  24. ll a1,b1,a2,b2;
  25.  
  26. a1=x1-x2;
  27. b1=y1-y2;
  28.  
  29. a2=x3-x4;
  30. b2=y3-y4;
  31.  
  32. long double d1=sqrt(a1*a1+b1*b1);
  33. long double d2=sqrt(a2*a2+b2*b2);
  34.  
  35. return (a1*a2+b1*b2)/(d1*d2);
  36. }
  37.  
  38. void square(ll q1, ll q2, ll q3, ll q4)
  39. {
  40. ll x1,x2,y1,y2,x3,y3,x4,y4;
  41. long double d1,d2,d3,d4,w1,w2,w3,w4;
  42.  
  43. if(p>0) return;
  44. x1=x[q1];y1=y[q1];
  45. x2=x[q2];y2=y[q2];
  46. x3=x[q3];y3=y[q3];
  47. x4=x[q4];y4=y[q4];
  48.  
  49. d1=dist(x1,y1,x2,y2);
  50. d2=dist(x2,y2,x3,y3);
  51. d3=dist(x3,y3,x4,y4);
  52. d4=dist(x4,y4,x1,y1);
  53. if(d1==d2&&d2==d3&&d3==d4)
  54. {
  55. w1=getcos(x2,y2,x1,y1,x2,y2,x3,y3);
  56. w2=getcos(x3,y3,x2,y2,x3,y3,x4,y4);
  57. w3=getcos(x4,y4,x3,y3,x4,y4,x1,y1);
  58. w4=getcos(x1,y1,x4,y4,x1,y1,x2,y2);
  59.  
  60. if(w1==w2&&w2==w3&&w3==w4&&w4==0)p=1;
  61. }
  62. return;
  63. }
  64.  
  65. void rectangle(ll q1, ll q2, ll q3, ll q4)
  66. {
  67. ll x1,x2,y1,y2,x3,y3,x4,y4;
  68. long double d1,d2,d3,d4,w1,w2,w3,w4;
  69.  
  70. if(p>0) return;
  71. x1=x[q1];y1=y[q1];
  72. x2=x[q2];y2=y[q2];
  73. x3=x[q3];y3=y[q3];
  74. x4=x[q4];y4=y[q4];
  75.  
  76. d1=dist(x1,y1,x2,y2);
  77. d2=dist(x2,y2,x3,y3);
  78. d3=dist(x3,y3,x4,y4);
  79. d4=dist(x4,y4,x1,y1);
  80. if(d1==d3&&d2==d4)
  81. {
  82. w1=getcos(x2,y2,x1,y1,x2,y2,x3,y3);
  83. w2=getcos(x3,y3,x2,y2,x3,y3,x4,y4);
  84. w3=getcos(x4,y4,x3,y3,x4,y4,x1,y1);
  85. w4=getcos(x1,y1,x4,y4,x1,y1,x2,y2);
  86.  
  87. if(w1==w2&&w2==w3&&w3==w4&&w4==0)p=2;
  88. }
  89. return;
  90. }
  91.  
  92. void rhombus(ll q1, ll q2, ll q3, ll q4)
  93. {
  94. ll x1,x2,y1,y2,x3,y3,x4,y4;
  95. long double d1,d2,d3,d4,w1,w2,w3,w4;
  96.  
  97. if(p>0) return;
  98. x1=x[q1];y1=y[q1];
  99. x2=x[q2];y2=y[q2];
  100. x3=x[q3];y3=y[q3];
  101. x4=x[q4];y4=y[q4];
  102.  
  103. d1=dist(x1,y1,x2,y2);
  104. d2=dist(x2,y2,x3,y3);
  105. d3=dist(x3,y3,x4,y4);
  106. d4=dist(x4,y4,x1,y1);
  107. if(d1==d2&&d2==d3&&d3==d4)
  108. {
  109. w1=getcos(x2,y2,x1,y1,x2,y2,x3,y3);
  110. w2=getcos(x3,y3,x2,y2,x3,y3,x4,y4);
  111. w3=getcos(x4,y4,x3,y3,x4,y4,x1,y1);
  112. w4=getcos(x1,y1,x4,y4,x1,y1,x2,y2);
  113.  
  114. if(w1==w3&&w2==w4)p=3;
  115. }
  116. return;
  117. }
  118.  
  119. void parallelogram(ll q1, ll q2, ll q3, ll q4)
  120. {
  121. ll x1,x2,y1,y2,x3,y3,x4,y4;
  122. long double d1,d2,d3,d4,w1,w2,w3,w4;
  123.  
  124. if(p>0) return;
  125. x1=x[q1];y1=y[q1];
  126. x2=x[q2];y2=y[q2];
  127. x3=x[q3];y3=y[q3];
  128. x4=x[q4];y4=y[q4];
  129.  
  130. d1=dist(x1,y1,x2,y2);
  131. d2=dist(x2,y2,x3,y3);
  132. d3=dist(x3,y3,x4,y4);
  133. d4=dist(x4,y4,x1,y1);
  134. if(d1==d3&&d2==d4)
  135. {
  136. w1=getcos(x2,y2,x1,y1,x2,y2,x3,y3);
  137. w2=getcos(x3,y3,x2,y2,x3,y3,x4,y4);
  138. w3=getcos(x4,y4,x3,y3,x4,y4,x1,y1);
  139. w4=getcos(x1,y1,x4,y4,x1,y1,x2,y2);
  140.  
  141. if(w1==w3&&w2==w4)p=4;
  142. }
  143. return;
  144. }
  145.  
  146. int main()
  147. {
  148. scanf("%d", &t);
  149. for(tt=0;tt<t;tt++)
  150. {
  151. p=0;
  152. scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &x[1], &y[1], &x[2], &y[2], &x[3], &y[3], &x[4], &y[4]);
  153.  
  154. for(i=1;i<4;i++)
  155. if(p==0)
  156. for(j=i+1;j<5;j++)
  157. if(x[i]==x[j]&&y[i]==y[j])
  158. {
  159. p=5;
  160. break;
  161. }
  162.  
  163. square(1,2,3,4);square(1,2,4,3);square(1,3,2,4);square(1,3,4,2);square(1,4,2,3);square(1,4,3,2);
  164. square(2,1,3,4);square(2,1,4,3);square(2,3,1,4);square(2,3,4,1);square(2,4,1,3);square(2,4,3,1);
  165. square(3,1,2,4);square(3,1,4,2);square(3,2,1,4);square(3,2,4,1);square(3,4,1,2);square(3,4,2,1);
  166. square(4,1,2,3);square(4,1,3,2);square(4,2,1,3);square(4,2,3,1);square(4,3,1,2);square(4,3,2,1);
  167.  
  168. rectangle(1,2,3,4);rectangle(1,2,4,3);rectangle(1,3,2,4);rectangle(1,3,4,2);rectangle(1,4,2,3);rectangle(1,4,3,2);
  169. rectangle(2,1,3,4);rectangle(2,1,4,3);rectangle(2,3,1,4);rectangle(2,3,4,1);rectangle(2,4,1,3);rectangle(2,4,3,1);
  170. rectangle(3,1,2,4);rectangle(3,1,4,2);rectangle(3,2,1,4);rectangle(3,2,4,1);rectangle(3,4,1,2);rectangle(3,4,2,1);
  171. rectangle(4,1,2,3);rectangle(4,1,3,2);rectangle(4,2,1,3);rectangle(4,2,3,1);rectangle(4,3,1,2);rectangle(4,3,2,1);
  172.  
  173. rhombus(1,2,3,4);rhombus(1,2,4,3);rhombus(1,3,2,4);rhombus(1,3,4,2);rhombus(1,4,2,3);rhombus(1,4,3,2);
  174. rhombus(2,1,3,4);rhombus(2,1,4,3);rhombus(2,3,1,4);rhombus(2,3,4,1);rhombus(2,4,1,3);rhombus(2,4,3,1);
  175. rhombus(3,1,2,4);rhombus(3,1,4,2);rhombus(3,2,1,4);rhombus(3,2,4,1);rhombus(3,4,1,2);rhombus(3,4,2,1);
  176. rhombus(4,1,2,3);rhombus(4,1,3,2);rhombus(4,2,1,3);rhombus(4,2,3,1);rhombus(4,3,1,2);rhombus(4,3,2,1);
  177.  
  178. parallelogram(1,2,3,4);parallelogram(1,2,4,3);parallelogram(1,3,2,4);parallelogram(1,3,4,2);parallelogram(1,4,2,3);parallelogram(1,4,3,2);
  179. parallelogram(2,1,3,4);parallelogram(2,1,4,3);parallelogram(2,3,1,4);parallelogram(2,3,4,1);parallelogram(2,4,1,3);parallelogram(2,4,3,1);
  180. parallelogram(3,1,2,4);parallelogram(3,1,4,2);parallelogram(3,2,1,4);parallelogram(3,2,4,1);parallelogram(3,4,1,2);parallelogram(3,4,2,1);
  181. parallelogram(4,1,2,3);parallelogram(4,1,3,2);parallelogram(4,2,1,3);parallelogram(4,2,3,1);parallelogram(4,3,1,2);parallelogram(4,3,2,1);
  182.  
  183. if(p==1)printf("SQUARE\n");else
  184. if(p==2)printf("RECTANGLE\n");else
  185. if(p==3)printf("RHOMBUS\n");else
  186. if(p==4)printf("PARALLELOGRAM\n");else
  187. if(p==0)printf("QUADRILATERAL\n");else
  188. printf("NONE\n");
  189. }
  190. return 0;
  191. }
  192.  
Success #stdin #stdout 0s 3360KB
stdin
Standard input is empty
stdout
Standard output is empty