Advertisement
Guest User

Untitled

a guest
Jan 24th, 2012
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. //SkyHawk, CMC MSU
  2.  
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <list>
  6. #include <string>
  7. #include <vector>
  8. #include <iterator>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <cstring>
  12. #include <set>
  13. #include <list>
  14. #include <queue>
  15.  
  16. using namespace std;
  17.  
  18. #define FOR(i,n) for(int i = 0;i < n;++i)
  19. #define PII pair<int,int>
  20.  
  21. //======================================================================
  22. //Checking, is point (0,0) in the triangle
  23. /*
  24.  * Options:
  25.  * IN_TRIANGLE_LOG - writing log
  26.  */
  27.  
  28. inline int inTriangle(long long x1,long long y1,long long x2,long long y2,
  29.     long long x3,long long y3)
  30. {
  31.     #ifdef IN_TRIANGLE_LOG
  32.         cerr << "inTriangle(): " << x1 << " " << y1 << " " << x2 << " " <<
  33.             y2 << " " << x3 << " " << y3;
  34.     #endif
  35.    
  36.     long long d1 = x1*y2 - y1*x2;
  37.     long long d2 = x2*y3 - y2*x3;
  38.     long long d3 = x3*y1 - y3*x1;
  39.     if((d1>=0) == (d2>=0) && (d1>=0) == (d3>=0))
  40.     {
  41.         if(d1 && d2 && d3)
  42.             return 2;
  43.         else
  44.             return 1;
  45.     }
  46.     return 0;
  47. }
  48.  
  49. int main(int argc, char** argv)
  50. {
  51.     freopen("INPUT.TXT","r",stdin);
  52.     freopen("OUTPUT.TXT","w",stdout);
  53.     int x1,x2,x3,y1,y2,y3,x,y;
  54.     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x >> y;
  55.     x1-=x;
  56.     x2-=x;
  57.     x3-=x;
  58.     y1-=y;
  59.     y2-=y;
  60.     y3-=y;
  61.     cout << (inTriangle(x1,y1,x2,y2,x3,y3)>0?"In":"Out") << endl;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement