Advertisement
Guest User

bombs

a guest
May 28th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. //#define double long double
  6.  
  7. const int M = 1010;
  8. const double eps = 1e-7;
  9.  
  10. struct Point {
  11.     double x, y;
  12.  
  13.     Point(): x(0), y(0) {}
  14.     Point(double x, double y): x(x), y(y) {}
  15.  
  16.     Point operator + (const Point &to) const {
  17.         return Point(x + to.x, y + to.y);
  18.     }
  19.     Point operator - (const Point &to) const {
  20.         return Point(x - to.x, y - to.y);
  21.     }
  22.  
  23.     Point operator * (const double c) const {
  24.         return Point(x * c, y * c);
  25.     }
  26.     Point operator / (const double c) const {
  27.         return Point(x / c, y / c);
  28.     }
  29.  
  30.     bool operator == (const Point &to) const {
  31.         return fabs(x - to.x) + fabs(y - to.y) <= eps;
  32.     }
  33.  
  34.     double sqlen() const {
  35.         return x * x + y * y;
  36.     }
  37.     double len() const {
  38.         return sqrt(sqlen());
  39.     }
  40.  
  41.     Point norm() const {
  42.         return Point(x / len(), y / len());
  43.     }
  44.     Point perp() const {
  45.         return Point(-y, x);
  46.     }
  47.  
  48.     double ang() {
  49.         if (x >= 0 && y >= 0)
  50.             return y;
  51.         if (x < 0 && y >= 0)
  52.             return 1 - x;
  53.         if (x < 0 && y < 0)
  54.             return 2 - y;
  55.         if (x >= 0 && y < 0)
  56.             return 3 + x;
  57.     }
  58. };
  59.  
  60. const Point zero;
  61.  
  62. int n;
  63. Point p[M];
  64. double r;
  65.  
  66. void read() {
  67.     cin >> n;
  68.     for (int i = 0; i < n; ++i)
  69.         cin >> p[i].x >> p[i].y;
  70.     cin >> r;
  71. }
  72.  
  73. int run(Point pivot) {
  74.     for (int i = 0; i < n; ++i)
  75.         p[i] = p[i] - pivot;
  76.  
  77.     int bon = 0, tot = 0, ans = 0;
  78.     vector<pair<double, int>> segments;
  79.  
  80.     for (int i = 0; i < n; ++i)
  81.         if (p[i] == zero) {
  82.             ++bon;
  83.         } else {
  84.             Point d = p[i] / 2.0;
  85.             Point perp = d.perp().norm();
  86.             if (d.sqlen() > r * r)
  87.                 continue;
  88.             double len = sqrt(r * r - d.sqlen());
  89.             Point from = d - (perp * len);
  90.             Point to = d + (perp * len);
  91.  
  92.             assert(fabs(from.len() - r) <= eps);
  93.             assert(fabs(to.len() - r) <= eps);
  94.  
  95.             double fromAng = from.norm().ang() - eps;
  96.             double toAng = to.norm().ang() + eps;
  97.  
  98.             if (fromAng > toAng)
  99.                 ++tot;
  100.  
  101.             segments.emplace_back(toAng, -1);
  102.             segments.emplace_back(fromAng, 1);
  103.         }
  104.  
  105.     sort(segments.begin(), segments.end());
  106.     for (int i = 0; i < (int) segments.size(); ++i) {
  107.         pair<double, int> x = segments[i];
  108.         ans = max(ans, tot);
  109.         tot += x.second;
  110.         assert(tot >= 0);
  111.     }
  112.     ans = max(ans, tot);
  113.  
  114.     return ans + bon;
  115. }
  116.  
  117. void kill() {
  118.     int ans = 0;
  119.     for (int i = 0; i < n; ++i)
  120.         ans = max(ans, run(p[i]));
  121.     cout << ans << "\n";
  122. }
  123.  
  124. int main() {
  125. #ifndef LOCAL
  126.     freopen("bombing.in", "r", stdin);
  127.     freopen("bombing.out", "w", stdout);
  128. #endif
  129.     read();
  130.     kill();
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement