ErnestGalbrun

Untitled

Dec 17th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1.  
  2. using namespace std;
  3.  
  4. struct Point {
  5.     int x;
  6.     int y;
  7.  
  8.     auto operator<=>(const Point &) const = default;
  9.  
  10.     auto operator+(const Point &b) const {
  11.         return Point{.x = x + b.x, .y = y + b.y};
  12.     }
  13.  
  14.     void operator+=(const Point &b) {
  15.         x += b.x;
  16.         y += b.y;
  17.     }
  18. };
  19.  
  20. int main() {
  21.     auto start = absl::Now();
  22.  
  23.     int x0 = 94;
  24.     int x1 = 151;
  25.     int y0 =-156;
  26.     int y1 =-103;
  27.  
  28.     auto isOk = [&](const Point& p){
  29.         return p.x >= x0 && p.x <=x1 && p.y >= y0 && p.y <= y1;
  30.     };
  31.  
  32.     int ans = 0;
  33.     for (int vx = 1; vx<=x1; ++vx) {
  34.         for(int vy = y0; vy <= abs(y0); ++vy) {
  35.             Point v = {.x = vx, .y = vy};
  36.             Point p = {.x = 0, .y = 0};
  37.             while(p.x <= x1 && p.y >= y0) {
  38.                 p += v;
  39.                 v.y -=1;
  40.                 if (v.x >0) v.x--;
  41.                 if (isOk(p)) {
  42.                     ans++;
  43.                     break;
  44.                 }
  45.             }
  46.         }
  47.     }
  48.     cout << ans << endl;
  49.     cout << absl::Now() - start << endl;
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment