Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #define eps (1e-6)
- using namespace std;
- typedef long long LL;
- struct vect {
- LL x, y;
- vect() {}
- vect(LL a, LL b) {
- x = a, y = b;
- }
- void read() {
- cin >> x >> y;
- }
- };
- vect operator - (vect a, vect b) {
- return vect(a.x - b.x, a.y - b.y);
- }
- LL operator * (vect a, vect b) {
- return a.x * b.x + a.y * b.y;
- }
- LL rad, q, n, A, B, C;
- vect pos, vel;
- bool check(LL x, LL y) {
- if ((vect(x, y) - pos) * vel >= 0) {
- if (abs(A * x + B * y + C) / sqrt(double(A * A + B * B)) * 1000 - rad - q > eps)
- return false;
- return true;
- }
- return false;
- }
- LL count_segment(LL x1, LL x2, LL y) {
- if (abs(x1) % 2 != y % 2)
- x1++;
- if (abs(x2) % 2 != y % 2)
- x2--;
- if (x2 >= x1)
- return (x2 - x1) / 2 + 1;
- return 0;
- }
- int main() {
- freopen("spacepin.in", "r", stdin);
- freopen("spacepin.out", "w", stdout);
- cin >> rad >> n >> q;
- pos.read();
- vel.read();
- A = vel.y, B = - vel.x;
- C = - A * pos.x - B * pos.y;
- LL res = 0;
- for (LL y = 0; y < n; y++) {
- double x_mid = - double(B * y + C) / A;
- LL x1 = LL(x_mid);
- LL l = - y - 1, r = min(x1 + 1, y + 1);
- LL mem_x1 = r - 1;
- while (l + 1 < r) {
- LL mid = (l + r) / 2;
- if (check(mid, y))
- r = mid;
- else
- l = mid;
- }
- res += count_segment(r, mem_x1, y);
- l = max(x1, - y - 1), r = y + 1;
- LL mem_l = l + 1;
- while (l + 1 < r) {
- LL mid = (l + r) / 2;
- if (check(mid, y))
- l = mid;
- else
- r = mid;
- }
- res += count_segment(mem_l, l, y);
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement