Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- const double eps=0.000001;
- struct point {
- double x,y;
- };
- struct Vector {
- long double x,y;
- Vector() = default;
- Vector (int x,int y): x(x),y(y) {}
- Vector operator * (int b) { return Vector(x*b,y*b); }
- Vector operator + (Vector v2) {return Vector(x+v2.x,y+v2.y); }
- };
- struct line {
- long double a,b,c;
- line (point p1, point p2) {
- a = p1.y - p2.y;
- b = p2.x - p1.x;
- c = -a*p2.x - p1.y*b;
- }
- };
- struct segment {
- point a,b;
- segment (point q, point w) {
- a=q;
- b=w;
- }
- };
- void printPoint (point p) {
- cout<<p.x<<" "<<p.y<<"\n";
- }
- void printVector (Vector p) {
- cout<<p.x<<" "<<p.y<<"\n";
- }
- double vectorLength(Vector a) {
- return a.x*a.x+a.y*a.y;
- }
- double pointDist (point a, point b) {
- return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
- }
- int dotproduct (Vector a, Vector b) {
- return a.x*b.x + a.y*b.y;
- }
- int crossproduct (Vector a, Vector b) {
- return a.x*b.y - a.y*b.x;
- }
- int main() {
- int a;
- a=3;
- vector <point> points(a+1);
- point C;
- for (int i=0;i<a;i++) cin >> points[i].x >> points[i].y;
- cin >> C.x >> C.y;
- for (int i=0;i<a;i++) {
- if (points[i].x == C.x && points[i].y == C.y)
- {
- cout<<"In"; return 0;
- }
- }
- for (int i=0;i<a;i++) {
- points[i].x-= C.x;
- points[i].y-= C.y;
- }
- points[a] = points[0];
- int ans = 0;
- int weight[a];
- for (int i=0;i<a;i++) weight[i] = 0;
- for (int i=0;i<a;i++) {
- if (points[i].y > points[i+1].y) weight[i]++;
- if (points[i].y < points[i+1].y) weight[(i+1)%a]++;
- }
- for (int i=0;i<a;i++) {
- if (points[i].y == 0 && points[i].x >= 0) ans+= weight[i];
- if (C.x == points[i].x && C.y == points[i].y) {
- cout<<"In"; return 0;
- }
- }
- for (int i=0;i<a;i++) {
- if (points[i].y * points[i+1].y < 0) {
- long double x1,x2,y1,y2;
- x1 = points[i].x;
- x2 = points[i+1].x;
- y1 = points[i].y;
- y2 = points[i+1].y;
- long double inter;
- inter= min(x1,x2) + abs(x2-x1) * max(y1,y2) / (abs(y1) + abs(y2));
- if (inter >= 0) ans++;
- }
- }
- if (ans%2 == 1) cout<<"In"; else cout<<"Out";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement