Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4. #include <cmath>
  5. using namespace std;
  6. const double eps=0.000001;
  7. struct point {
  8. double x,y;
  9. };
  10. struct Vector {
  11. long double x,y;
  12. Vector() = default;
  13. Vector (int x,int y): x(x),y(y) {}
  14. Vector operator * (int b) { return Vector(x*b,y*b); }
  15. Vector operator + (Vector v2) {return Vector(x+v2.x,y+v2.y); }
  16. };
  17. struct line {
  18. long double a,b,c;
  19. line (point p1, point p2) {
  20. a = p1.y - p2.y;
  21. b = p2.x - p1.x;
  22. c = -a*p2.x - p1.y*b;
  23. }
  24. };
  25. struct segment {
  26. point a,b;
  27. segment (point q, point w) {
  28. a=q;
  29. b=w;
  30. }
  31. };
  32. void printPoint (point p) {
  33. cout<<p.x<<" "<<p.y<<"\n";
  34. }
  35. void printVector (Vector p) {
  36. cout<<p.x<<" "<<p.y<<"\n";
  37. }
  38. double vectorLength(Vector a) {
  39. return a.x*a.x+a.y*a.y;
  40. }
  41. double pointDist (point a, point b) {
  42. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  43. }
  44.  
  45. int dotproduct (Vector a, Vector b) {
  46. return a.x*b.x + a.y*b.y;
  47. }
  48. int crossproduct (Vector a, Vector b) {
  49. return a.x*b.y - a.y*b.x;
  50. }
  51. int main() {
  52.  
  53. int a;
  54. a=3;
  55.  
  56. vector <point> points(a+1);
  57. point C;
  58. for (int i=0;i<a;i++) cin >> points[i].x >> points[i].y;
  59. cin >> C.x >> C.y;
  60. for (int i=0;i<a;i++) {
  61. if (points[i].x == C.x && points[i].y == C.y)
  62. {
  63. cout<<"In"; return 0;
  64. }
  65. }
  66. for (int i=0;i<a;i++) {
  67. points[i].x-= C.x;
  68. points[i].y-= C.y;
  69.  
  70. }
  71. points[a] = points[0];
  72. int ans = 0;
  73. int weight[a];
  74.  
  75. for (int i=0;i<a;i++) weight[i] = 0;
  76. for (int i=0;i<a;i++) {
  77. if (points[i].y > points[i+1].y) weight[i]++;
  78. if (points[i].y < points[i+1].y) weight[(i+1)%a]++;
  79.  
  80. }
  81. for (int i=0;i<a;i++) {
  82. if (points[i].y == 0 && points[i].x >= 0) ans+= weight[i];
  83. if (C.x == points[i].x && C.y == points[i].y) {
  84. cout<<"In"; return 0;
  85.  
  86. }
  87. }
  88.  
  89. for (int i=0;i<a;i++) {
  90. if (points[i].y * points[i+1].y < 0) {
  91. long double x1,x2,y1,y2;
  92.  
  93. x1 = points[i].x;
  94. x2 = points[i+1].x;
  95. y1 = points[i].y;
  96. y2 = points[i+1].y;
  97. long double inter;
  98. inter= min(x1,x2) + abs(x2-x1) * max(y1,y2) / (abs(y1) + abs(y2));
  99. if (inter >= 0) ans++;
  100.  
  101. }
  102. }
  103. if (ans%2 == 1) cout<<"In"; else cout<<"Out";
  104.  
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement