HDU 4562 守护雅典娜(动态规划)
来源:互联网 发布:vb中怎么计算运行次数 编辑:程序博客网 时间:2024/05/04 23:37
答案分为三种只能只有包含雅典娜的塔,只有包含怪兽的塔,包含雅典娜和怪兽的塔的和。
使用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 0
- HDU 4562 守护雅典娜(动态规划)
- HDU 4562 守护雅典娜(金山复赛第二场)
- hdu 4562 守护雅典娜(计算几何+dp)
- 拯救雅典娜——倒序动态规划
- hdu4562 守护雅典娜
- HDU4562-守护雅典娜
- hdu4562 守护雅典娜 DP
- HDOJ - 4562/西山居复赛2 守护雅典娜
- HDU4562 守护雅典娜(DP)
- 【动态规划】木马级守护进程
- 雅典娜
- 动态规划-hdu 2955
- hdu 动态规划
- HDU动态规划专题
- HDU 1028 动态规划
- hdu 1078 动态规划
- HDU 2069 动态规划
- HDU 1160 动态规划
- Linux后台运行过程查看
- myeclipse更换workspace后,出现warining问题的解决方案
- C++primer__泛型算法-泛型算法结构
- hive与hbase关联表的创建,外表方式
- LeetCode 26 : Remove Duplicates from Sorted Array (Java)
- HDU 4562 守护雅典娜(动态规划)
- Queue接口_Enumeration接口JAVA129-130
- 闲来无事总结的各种[XXX]的用法……高手勿入……内部低能……
- POJ.2420.A Star not a Tree.模拟退火.0ms
- HDU 1062:Text Reverse【水】
- Android:shape的使用详解(2)
- java代理
- 图像的直方图均衡化和比特平面分层
- leetcode_Peeking Iterator