【LA 2572】Viva Confetti, Kanazawa 2002 (计算几何,圆)

Description

n n <script type="math/tex" id="MathJax-Element-31">n</script>个圆盘依次摆到桌面上,给出顺序、圆心位置和半径,求最后有多少个圆盘可见?
数据保证轻微扰动后不改变结果

Code

感觉这题挺巧妙的。
可以发现所有的可见部分的轮廓都是由圆弧组成的。
对于每个圆,求出边缘上的小圆弧,取每段圆弧的中点,判断其的内外部分的最上层分别属于哪个圆盘并计数即可。

Source

/************************************************
 * Au: Hany01
 * Date: Feb 12th, 2018
 * Prob: [LA 2572] Viva Confetti, Kanazawa 2002
 * Email: hany01@foxmail.com
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define fir first
#define sec second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia
#define sqr(x) ((x) * (x))

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read()
{
    register int _, __; register char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

inline void File()
{
#ifdef hany01
    freopen("la2572.in", "r", stdin);
    freopen("la2572.out", "w", stdout);
#endif
}

const double eps = 5e-13, Pi = acos(-1.0);

int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; }

struct Point
{
    double x, y;
    Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }

struct Circle
{
    Point O; double r;
    Circle(Point O = Point(0, 0), double r = 0): O(O), r(r) {}
    Point point(double rad) { return Point(O.x + cos(rad) * r, O.y + sin(rad) * r); }
};

double Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; }
double Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; }
double Length(Vector V) { return sqrt(Dot(V, V)); }
double Angle(Vector V) { return atan2(V.y, V.x); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }

const int maxn = 105;

int n, cnt;
Circle C[maxn], C_;
double lst[maxn << 1];

inline void GetCircleIntersection(Circle C1, Circle C2)
{
    if (C1.r < C2.r) swap(C1, C2);
    double d = Length(C1.O - C2.O), a = Angle(C2.O - C1.O);
    if (dcmp(d - C1.r - C2.r) > 0 || dcmp(d - C1.r + C2.r) < 0) return ;
    double da = acos((sqr(C1.r) + sqr(d) - sqr(C2.r)) / (2 * C1.r * d));
    if (!dcmp(da)) lst[++ cnt] = a;
    else lst[++ cnt] = a + da, lst[++ cnt] = a - da;
}

int top(Point P) {
    Fordown(i, n, 1) if (dcmp(Length(P - C[i].O) - C[i].r) < 0) return i;
    return 0;
}

int main()
{
    File();
    while (scanf("%d", &n) != EOF && n) {
        For(i, 1, n) scanf("%lf%lf%lf", &C[i].O.x, &C[i].O.y, &C[i].r);
        int isvisual[maxn]; Set(isvisual, 0);
        For(i, 1, n) {
            cnt = 2, lst[1] = 0, lst[2] = 2 * Pi;
            For(j, 1, n) if (i != j) GetCircleIntersection(C[i], C[j]);
            For(j, 1, cnt) {
                while (dcmp(lst[j]) < 0) lst[j] += Pi * 2;
                while (dcmp(lst[j] - Pi * 2) > 0) lst[j] -= Pi * 2;
            }
            sort(lst + 1, lst + 1 + cnt);
            For(j, 1, cnt - 1) {
                register double rad = (lst[j] + lst[j + 1]) / 2;
                For(k, -1, 1) if (k) C_ = C[i], C_.r += k * eps, isvisual[top(C_.point(rad))] = 1;
            }
        }
        register int Ans = 0;
        For(i, 1, n) if (isvisual[i]) ++ Ans;
        printf("%d\n", Ans);
    }
    return 0;
}
//闻君有两意,故来相决绝。
//    -- 卓文君《白头吟》
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值