fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
  5. template<class T>
  6. struct Point {
  7. typedef Point P;
  8. T x, y;
  9. explicit Point(T x=0, T y=0) : x(x), y(y) {}
  10. bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
  11. bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
  12. P operator+(P p) const { return P(x+p.x, y+p.y); }
  13. P operator-(P p) const { return P(x-p.x, y-p.y); }
  14. P operator*(T d) const { return P(x*d, y*d); }
  15. P operator/(T d) const { return P(x/d, y/d); }
  16. T dot(P p) const { return x*p.x + y*p.y; }
  17. T cross(P p) const { return x*p.y - y*p.x; }
  18. T cross(P a, P b) const { return (a-*this).cross(b-*this); }
  19. T dist2() const { return x*x + y*y; }
  20. double dist() const { return sqrt((double)dist2()); }
  21. // angle to x-axis in interval [-pi, pi]
  22. double angle() const { return atan2(y, x); }
  23. double angledegree() const { return atan2(y, x) * 180.0 / acos(-1); }
  24.  
  25. P unit() const { return *this/dist(); } // makes dist()=1
  26. P perp() const { return P(-y, x); } // rotates +90 degrees
  27. P normal() const { return perp().unit(); }
  28. // returns point rotated 'a' radians ccw around the origin
  29. P rotate(double a) const {
  30. return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
  31. friend ostream& operator<<(ostream& os, P p) {
  32. return os << "(" << p.x << "," << p.y << ")"; }
  33. };
  34.  
  35. void solve(){
  36. Point<double> a, b; cin >> a.x >> a.y >> b.x >> b.y;
  37. b = b - a;
  38. double alpha = b.angledegree();
  39.  
  40. int qq; cin >> qq;
  41. for(int q = 0; q < qq; q++) {
  42. Point<double> p; cin >> p.x >> p.y;
  43. p = p - a;
  44. double beta = p.angledegree();
  45. beta -= alpha;
  46.  
  47. if(abs(0 - beta) < 1e-6){
  48. double d1 = b.dist2();
  49. double d2 = p.dist2();
  50. if(d1 > d2) cout << "ON_SEGMENT\n";
  51. else cout << "ONLINE_FRONT\n";
  52. }
  53. else if(abs(180 - abs(beta)) < 1e-6) cout << "ONLINE_BACK\n";
  54. else {
  55. if(beta > 0) cout << "COUNTER_CLOCKWISE\n";
  56. else cout << "CLOCKWISE\n";
  57. }
  58. }
  59. }
  60.  
  61. int main(){
  62. ios_base::sync_with_stdio(0);
  63. cin.tie(0); cout.tie(0);
  64.  
  65. cout << fixed << setprecision(8);
  66. solve();
  67. }
Success #stdin #stdout 0s 5320KB
stdin
0 0 2 0
2
-1 1
-1 -1
stdout
COUNTER_CLOCKWISE
CLOCKWISE