fork download
  1. // i wants to take ioi
  2. //binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. #define int long long
  8. #define nn "\n"
  9. #define pi pair<int, int>
  10. #define fi first
  11. #define se second
  12. #define lb lower_bound
  13. #define ub upper_bound
  14. #define eb emplace_back
  15. #define pb push_back
  16. #define TASK "TUGIAC"
  17.  
  18. #define ms(a, x) memset(a, x, sizeof(a))
  19. #define all(a) a.begin(), a.end()
  20. #define All(a, n) a + 1, a + 1 + n
  21.  
  22. #define LOG 19
  23.  
  24. const int INF = 1e18;
  25. const int mod = 1e9;
  26. const int N = 1e5 + 5;
  27. const int MOD = 998244353;
  28.  
  29. int bit[200000];
  30.  
  31. struct Point{
  32. int x, y;
  33. };
  34.  
  35. Point p[5];
  36.  
  37. void nhap(){
  38. for(int i = 1; i <= 4; i++)
  39. cin >> p[i].x >> p[i].y;
  40. }
  41.  
  42. int cross(Point a, Point b, Point c){
  43. return (b.x - a.x) * (c.y - a.y)
  44. - (b.y - a.y) * (c.x - a.x);
  45. }
  46.  
  47. int sign(int x){
  48. if(x > 0) return 1;
  49. if(x < 0) return -1;
  50. return 0;
  51. }
  52.  
  53. bool trenDoan(Point a, Point b, Point c){
  54. return min(a.x, b.x) <= c.x && c.x <= max(a.x, b.x)
  55. && min(a.y, b.y) <= c.y && c.y <= max(a.y, b.y)
  56. && cross(a, b, c) == 0;
  57. }
  58. bool giaoNhau(Point a, Point b, Point c, Point d){
  59. int u = cross(a, b, c);
  60. int v = cross(a, b, d);
  61. int w = cross(c, d, a);
  62. int z = cross(c, d, b);
  63. if(sign(u) * sign(v) < 0 && sign(w) * sign(z) < 0)
  64. return true;
  65. if(u == 0 && trenDoan(a, b, c)) return true;
  66. if(v == 0 && trenDoan(a, b, d)) return true;
  67. if(w == 0 && trenDoan(c, d, a)) return true;
  68. if(z == 0 && trenDoan(c, d, b)) return true;
  69. return false;
  70. }
  71.  
  72. long double dienTich(Point a, Point b, Point c){
  73. return fabsl(((long double)b.x - a.x) * ((long double)c.y - a.y) - ((long double)b.y - a.y) * ((long double)c.x - a.x)) / 2.0L;
  74. }
  75.  
  76. void solve(){
  77. for(int i = 1; i <= 4; i++){
  78. for(int j = i + 1; j <= 4; j++){
  79. if(p[i].x == p[j].x && p[i].y == p[j].y){
  80. cout << 0 << nn;
  81. return;
  82. }
  83. }
  84. }
  85. bool g1 = giaoNhau(p[1], p[2], p[3], p[4]);
  86. bool g2 = giaoNhau(p[2], p[3], p[4], p[1]);
  87. if(g1 || g2){
  88. Point a = p[1], b = p[2], c = p[3], d = p[4];
  89. long double dt = 0;
  90. if(g1){
  91. int vx = b.x - a.x;
  92. int vy = b.y - a.y;
  93. int ux = d.x - c.x;
  94. int uy = d.y - c.y;
  95. long double mau = (long double)vx * uy - (long double)vy * ux;
  96. if(mau == 0){
  97. cout << 0 << nn;
  98. return;
  99. }
  100. long double t = ((long double)(c.x - a.x) * uy - (long double)(c.y - a.y) * ux) / mau;
  101.  
  102. long double qx = a.x + t * vx;
  103. long double qy = a.y + t * vy;
  104.  
  105. dt = fabsl((long double)(a.x - qx) * (d.y - qy) - (long double)(a.y - qy) * (d.x - qx)) / 2.0L + fabsl((long double)(b.x - qx) * (c.y - qy) - (long double)(b.y - qy) * (c.x - qx)) / 2.0L;
  106. }
  107. else{
  108. a = p[2];
  109. b = p[3];
  110. c = p[4];
  111. d = p[1];
  112. int vx = b.x - a.x;
  113. int vy = b.y - a.y;
  114. int ux = d.x - c.x;
  115. int uy = d.y - c.y;
  116. long double mau = (long double)vx * uy - (long double)vy * ux;
  117. if(mau == 0){
  118. cout << 0 << nn;
  119. return;
  120. }
  121.  
  122. long double t = ((long double)(c.x - a.x) * uy - (long double)(c.y - a.y) * ux) / mau;
  123. long double qx = a.x + t * vx;
  124. long double qy = a.y + t * vy;
  125. dt = fabsl((long double)(p[1].x - qx) * (p[2].y - qy) - (long double)(p[1].y - qy) * (p[2].x - qx)) / 2.0L
  126. + fabsl((long double)(p[3].x - qx) * (p[4].y - qy)
  127. - (long double)(p[3].y - qy) * (p[4].x - qx)) / 2.0L;
  128. }
  129. if(dt == 0){
  130. cout << 0 << nn;
  131. return;
  132. }
  133. cout << 3 << nn;
  134. cout << fixed << setprecision(3) << dt << nn;
  135. return;
  136. }
  137.  
  138. int c1 = cross(p[1], p[2], p[3]);
  139. int c2 = cross(p[2], p[3], p[4]);
  140. int c3 = cross(p[3], p[4], p[1]);
  141. int c4 = cross(p[4], p[1], p[2]);
  142. if(c1 == 0 || c2 == 0 || c3 == 0 || c4 == 0){
  143. cout << 0 << nn;
  144. return;
  145. }
  146. int loai = 1;
  147. if(!(sign(c1) == sign(c2) && sign(c2) == sign(c3) && sign(c3) == sign(c4))) loai = 2;
  148.  
  149. long double dt = fabsl((long double)p[1].x * p[2].y - (long double)p[1].y * p[2].x + (long double)p[2].x * p[3].y - (long double)p[2].y *p[3].x + (long double)p[3].x * p[4].y - (long double)p[3].y * p[4].x + (long double)p[4].x * p[1].y - (long double)p[4].y * p[1].x) / 2.0L;
  150. if(dt == 0){
  151. cout << 0 << nn;
  152. return;
  153. }
  154. cout << loai << nn;
  155. cout << fixed << setprecision(3) << dt << nn;
  156. }
  157. signed main(){
  158. if(fopen(TASK".INP", "r")){
  159. freopen(TASK".INP", "r", stdin);
  160. freopen(TASK".OUT", "w", stdout);
  161. }
  162. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  163. nhap();
  164. solve();
  165. return (0 ^ 0);
  166. }
Success #stdin #stdout 0s 5320KB
stdin
1 1
4 2
5 3
2 4
stdout
1
6.000