Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C++
Posted by: Ivan Belonogov
Added: Jan 28, 2018 12:35 PM
Modified: Feb 13, 2018 9:17 AM
Views: 21
Tags: no tags
  1. struct pt {
  2.     ll x, y;
  3.     pt() {}
  4.     pt(ll xx, ll yy): x(xx), y(yy) {}
  5.     pt operator + (pt A) {
  6.         return pt(x + A.x, y + A.y);
  7.     }
  8.     pt operator - (pt A) {
  9.         return pt(x - A.x, y - A.y);
  10.     }
  11.     pt operator * (ll k) {
  12.         return pt(x * k, y * k);
  13.     }
  14.     pt operator / (ll k) {
  15.         assert(x % k == 0 && y % k == 0);
  16.         return pt(x / k, y / k);
  17.     }
  18.     ll operator * (pt A) {
  19.         return x * A.y - y * A.x;
  20.     }    
  21.     ll operator % (pt A) {
  22.         return x * A.x + y * A.y;
  23.     }
  24.     bool operator == (pt A) {
  25.         return x == A.x && y == A.y;
  26.     }
  27.     bool operator != (pt A) {
  28.         return x != A.x && y != A.y;
  29.     }
  30.     pt rotate() {
  31.         return pt(-y, x);
  32.     }
  33.     ll len2() {
  34.         return x * x + y * y;
  35.     }
  36.     dbl len() {
  37.         return sqrt(x * x + y * y);
  38.     }    
  39.     void read() {
  40.         scanf("%lld%lld", &x, &y);
  41.     }
  42. };    
  43.