Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4. #define double long double
  5. #define ff first
  6. #define ss second
  7. #define endl '\n'
  8. #define ii pair<int, int>
  9. #define mp make_pair
  10. #define mt make_tuple
  11. #define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  12. #define pb push_back
  13. #define vi vector<int>
  14. #define vii vector< ii >
  15. #define EPS 1e-9
  16. #define INF 1e18
  17. #define ROOT 1
  18. #define M 1000000007
  19. const double PI = acos(-1);
  20.  
  21. using namespace std;
  22.  
  23. inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
  24.  
  25. int gcd(int a, int b){
  26. if(a == 0) return b;
  27. else return gcd(b%a, a);
  28. }
  29.  
  30. struct point {
  31. double x, y;
  32. point() {}
  33. point(double x, double y) : x(x), y(y) {}
  34. };
  35.  
  36. struct line {
  37. double a,b,c;
  38. };
  39.  
  40. int32_t main(){
  41. DESYNC;
  42. int q = 0;
  43. int n;
  44. cin >> n;
  45. while(q++ < n){
  46. point a,b,c,d;
  47. cin >> a.x >> a.y >> c.x >> c.y >> b.x >> b.y >> d.x >> d.y;
  48.  
  49. point m1((a.x + b.x)/2., (a.y + b.y)/2.);
  50. point m2((c.x + d.x)/2., (c.y + d.y)/2.);
  51.  
  52. point v1(b.x-a.x, b.y-a.y);
  53. point v2(d.x-c.x, d.y-c.y);
  54.  
  55. point inv_v1(-v1.y, v1.x);
  56. point inv_v2(-v2.y, v2.x);
  57.  
  58. line l1, l2;
  59. l1.a = -inv_v1.y;
  60. l1.b = inv_v1.x;
  61. l1.c = -(l1.a*m1.x + l1.b*m1.y);
  62.  
  63. l2.a = -inv_v2.y;
  64. l2.b = inv_v2.x;
  65. l2.c = -(l2.a*m2.x + l2.b*m2.y);
  66.  
  67. double x, y;
  68. if(abs(l1.c*l2.b - l2.c*l1.b) <= EPS or abs(l1.a*l2.b - l2.a*l1.b) <= EPS) x = 0;
  69. else x = -(l1.c*l2.b - l2.c*l1.b)/(l1.a*l2.b - l2.a*l1.b);
  70. if(abs(l1.a*l2.c - l2.a*l1.c) <= EPS or abs(l1.a*l2.b - l2.a*l1.b) <= EPS) y = 0;
  71. else y = -(l1.a*l2.c - l2.a*l1.c)/(l1.a*l2.b - l2.a*l1.b);
  72. cout << fixed << setprecision(2) << "Caso #" << q << ": " << x << " " << y << endl;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement