hdu 5928 Birthday Gift

题解:先选出枚举一个点i作为坐标原点,然后以其他的点作极角排序(逆时针旋转)。然后 d[j][k] 代表 以j作为i的逆时针旋转凸包的最后一个点,存在于 i ~ j 中的点的个数为k个,(dp时只记录了i~j的单程的距离,最后一步没有合上。需要闭合的凸包的话还需要把 i ~ j 的距离(Length(i~j))给加上。

#include"bits/stdc++.h"
using namespace std;
const int MX = 100;
const int inf = 0x3f3f3f3f3f;
const double eps = -1e-12;
struct Point {
    double x, y;
    Point() {}
    Point(double x,double y):x(x),y(y) {}
} p[MX],V[MX];

typedef Point Vector;
int dcmp(double x) { //返回x的正负
    if(fabs(x)<eps)
        return 0;
    return x<0?-1:1;
}
Vector operator-(Vector A,Vector B) {
    return Vector(A.x - B.x, A.y - B.y);
}
Vector operator+(Vector A,Vector B) {
    return Vector(A.x + B.x, A.y + B.y);
}
Vector operator*(Vector A,double p) {
    return Vector(A.x*p, A.y*p);
}
Vector operator/(Vector A,double p) {
    return Vector(A.x/p, A.y/p);
}
bool operator<(const Point&a,const Point&b) {
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
bool operator==(const Point&a,const Point&b) {
    return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}
double Dot(Vector A,Vector B) { //点积
    return A.x*B.x+A.y*B.y;//如果改成整形记得加LL
}
double Cross(Vector A,Vector B) { //叉积
    return A.x*B.y-A.y*B.x;//如果改成整形记得加LL
}
//向量长度
double Length(Vector A) {
    return sqrt(Dot(A,A));
}
//2个向量之间的夹角
double Angle(Vector A,Vector B) {
    return acos(Dot(A,B)/Length(A)/Length(B));
}
//向量的极角
double angle(Vector v) {
    return atan2(v.y,v.x);
}

//极角排序
bool cmp(Point a, Point b) {
    return Cross(a,b) ? Cross(a,b) > 0 : Dot(a,a) < Dot(b,b);
}

double d[MX][MX];
int main() {
    int T,cas = 0;
    cin>>T;
    while(T--) {
        int n;
        double L;
        scanf("%d%lf",&n,&L);
        for(int i = 1; i <= n; i++) {
            scanf("%lf %lf",&p[i].x,&p[i].y);
        }
        int ans = 1;
        for(int i = 1; i <= n; i++) {
            int m = 0;
            for(int j = 1; j <= n; j++) {
                if(i == j) continue;
                if(p[j].y - p[i].y > eps) V[++m] = p[j]-p[i];   //
            }
            sort(V+1,V+1+m, cmp);

            for(int j = 0; j <= m; j++)
                for(int k = 0; k <= m; k++)
                    d[j][k] = inf;

            for(int j = 1; j <= m; j++) {
                double dis = Length(V[j]);
                if(L - dis < eps) continue;
                d[j][1] = dis;

                for(int k = j+1; k <= m; k++) {
                    double len = Length(V[k]-V[j]);
                    if(L - dis - len < eps) continue;

                    int cnt = 1;
                    for(int l = j+1; l < k; l++) {
                        if(Cross(V[k]-V[j],V[l]-V[j]) > eps) cnt++;     //枚举有多少个点在凸包内侧,用叉积判断,逆时针旋转为正
                    }

                    for(int l = 1; l <= j && l+cnt <= k; l++) { // 状态转移方程
                        if(L - d[j][l] - len < eps) continue;
                        d[k][l+cnt] = min(d[k][l+cnt], d[j][l] + len);
                    }
                }

                for(int l = 1; l <= m; l++){
                    if(L - d[j][l] - dis > eps){
                        ans = max(ans,l+1);
                    }
                }
            }
        }
        printf("Case #%d: %d\n",++cas, ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值