HDU 4562 守护雅典娜(动态规划)

答案分为三种只能只有包含雅典娜的塔,只有包含怪兽的塔,包含雅典娜和怪兽的塔的和。

使用dp可以分别计算包含雅典娜、怪兽的最厚塔层数,过程类似LIS。枚举这两种情况的塔数,求和计算第三种情况。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int maxn=1005;
struct Circle
{
    int x,y,r;
    bool checkIn(int sx,int sy)
    {
        sx-=x;
        sy-=y;
        return sx*sx+sy*sy<r*r;
    }
    bool checkOut(int sx,int sy)
    {
        sx-=x;
        sy-=y;
        return sx*sx+sy*sy>r*r;
    }

    bool operator <(const Circle & c) const
    {
        return r<c.r;
    }
};
bool judgeIn(const Circle &a,const Circle &b)
{
    int r=max(a.r,b.r)-min(a.r,b.r);
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)<r*r;
}
bool judgeOut(const Circle &a,const Circle &b)
{
    int r=a.r+b.r;
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)>r*r;
}
vector<Circle> a,b;
int dp1[maxn],dp2[maxn];
void solve(vector<Circle>& v,int *dp,int &ans)
{
    sort(v.begin(),v.end());
    for(int i=0; i<v.size(); ++i)
    {
        dp[i]=1;
        for(int j=0; j<i; ++j)
        {
            if(judgeIn(v[i],v[j]))
                dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,dp[i]);
    }
}
int main()
{
    int T,kase=0;
    scanf("%d",&T);
    while(T--)
    {
        int n,x,y;
        scanf("%d%d%d",&n,&x,&y);
        a.clear();
        b.clear();
        for(int i=1; i<=n; ++i)
        {
            Circle c;
            scanf("%d%d%d",&c.x,&c.y,&c.r);
            if(c.checkIn(0,0)&&c.checkOut(x,y))
                a.push_back(c);
            else if(c.checkIn(x,y)&&c.checkOut(0,0))
                b.push_back(c);
        }
        int ans=0;
        solve(a,dp1,ans);
        solve(b,dp2,ans);
        for(int i=0; i<a.size(); ++i)
        {
            for(int j=0; j<b.size(); ++j)
            {
                if(judgeOut(a[i],b[j]))
                    ans=max(dp1[i]+dp2[j],ans);
            }
        }
        printf("Case %d: %d\n",++kase,ans);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值