HDU 4562 守护雅典娜 (计算几何+DP)
守护雅典娜
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 740 Accepted Submission(s): 250
这里,我们可以建造的防御工具只有标准圆形状的防御墙,建立在雅典娜与怪物出生点之间的防御墙数目越多,胜利的希望就越大。这里,将问题简化到一个二维坐标系里,并且假设雅典娜的坐标为原点(0, 0),怪物出生点的坐标为(X, Y)。有N个给定圆心坐标与半径的防御墙可以供玩家选择建立,但要保证所有的圆都不发生相切或相交的情况。注意这些雅典娜位置与怪物出生点位置也不能在墙壁的边缘,即表示防御墙的圆上。点的面积与墙的厚度都很小,可以忽略不计。
记住,在游戏开始之后,怪物可以沿着任何轨迹,选择突破最少的圆形防御墙来到雅典娜的身边,而一个防御墙一旦被突破,它就会失去保护作用。所以,你的方案必须足够优秀。为了守护女神,快去找出最优的建设方案吧!
每组数据以三个整数N,X,Y开始,接下去的N行每行包括三个整数Xi,Yi,Ri,表示一个可以选择的圆心为(Xi, Yi)半径为Ri的防御墙。
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1000
3. 1 <= Ri <= 10 000
4. -10 000 <= X, Y, Xi, Yi <= 10 000,坐标不会相同
1 5 5
1 0 2
1 5 5
1 0 9
3 5 5
1 0 2
4 5 2
2 0 6
Case 2: 0
Case 3: 2
Statistic | Submit | Discuss | Note
析:首先先找出来两种圆,一种是只包含怪物的,另一种是只包含雅典娜的,因为都包含或者都不包含的没什么意义,排序,从小到大按半径,然后分别进行dp,最后肯定是包含的选出最多一个,然后再进行合并。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 10;
const int maxm = 1e5 + 10;
const int mod = 50007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Point{
int x, y;
Point() { }
Point(int xx, int yy) : x(xx), y(yy) { }
friend Point operator - (const Point &lhs, const Point &rhs){
return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}
}; int dist(Point p){
return sqr(p.x) + sqr(p.y);
} struct Circle{
Point c;
int r;
bool operator < (const Circle &c) const{
return r < c.r;
}
};
Circle c[maxn];
Point athene, monster; int isintersection(const Point &p, const Circle &c){
int d = dist(p - c.c);
return d - sqr(c.r);
} bool not_intersection(const Circle &c1, const Circle &c2){
int d = dist(c1.c - c2.c);
return d > sqr(c1.r + c2.r);
} bool isinclude(const Circle &c1, const Circle &c2){
int d = dist(c1.c - c2.c);
return sqr(c1.r - c2.r) > d;
} vector<Circle> aths, mos;
int f[maxn], g[maxn]; int main(){
monster.x = monster.y = 0;
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
mos.cl; aths.cl;
scanf("%d %d %d", &n, &athene.x, &athene.y);
for(int i = 0; i < n; ++i){
scanf("%d %d %d", &c[i].c.x, &c[i].c.y, &c[i].r);
int id1 = isintersection(athene, c[i]);
int id2 = isintersection(monster, c[i]);
if(id1 < 0 && id2 > 0) aths.push_back(c[i]);
else if(id1 > 0 && id2 < 0) mos.push_back(c[i]);
}
sort(aths.begin(), aths.end());
sort(mos.begin(), mos.end());
int ans = 0;
for(int i = 0; i < aths.sz; ++i){
f[i] = 1;
for(int j = 0; j < i; ++j)
if(isinclude(aths[i], aths[j])) f[i] = max(f[i], f[j] + 1);
ans = max(ans, f[i]);
}
for(int i = 0; i < mos.sz; ++i){
g[i] = 1;
for(int j = 0; j < i; ++j)
if(isinclude(mos[i], mos[j])) g[i] = max(g[i], g[j] + 1);
ans = max(ans, g[i]);
}
for(int i = 0; i < aths.sz; ++i)
for(int j = 0; j < mos.sz; ++j)
if(not_intersection(aths[i], mos[j])) ans = max(ans, f[i] + g[j]);
printf("Case %d: %d\n", kase, ans);
}
return 0;
}
HDU 4562 守护雅典娜 (计算几何+DP)的更多相关文章
- HDU 4562 守护雅典娜(dp)
守护雅典娜 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- HDU 1231 最大连续子序列 --- 入门DP
HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- hdu 4514 并查集+树形dp
湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 【转】雅典娜与宙斯的对话.(kerberos原理)
1 八月 2010 22:07:51关于Kerberos的对话(MIT)雅典娜与宙斯 雅典娜与宙斯关于地狱之门守护者的对话 Kerberos: Network Authentication Proto ...
随机推荐
- UI5-文档-4.28-Unit Test with QUnit
现在我们在应用程序中有了一个测试文件夹,我们可以开始增加我们的测试覆盖率. 实际上,到目前为止我们添加到应用程序中的每个特性都需要单独的测试用例.到目前为止,我们完全忽略了这一点,所以让我们为步骤23 ...
- UI5-文档-2.5-开发混合Web容器
开发混合Web容器 您可以将移动应用程序开发为混合应用程序,该混合应用程序由本机应用程序包装程序(例如PhoneGap)和HTML查看器组成,用于在用户界面上显示内容. 混合应用程序的优点是可以在应用 ...
- mysql使用一条sql删除多条数据
使用in delete from course where chour in(55,56,57); course:表名 chour:字段 55,56,57数据
- 集中化管理平台Saltstack安装配置
salt是一个异构平台基础设置管理工具(虽然我们通常只用在Linux上),使用轻量级的通讯器ZMQ,用Python写成的批量管理工具,完全开源,遵守Apache2协议,与Puppet,Chef功能类似 ...
- 关于EL表达式取值的问题
EL表达式取值时,如果没有指定作用域,EL表达式会自动按照作用域的大小,从小到大依次去找;比如${s},会自动按照"pageContext,request,session,applicati ...
- TZOJ 1242 求出前m大的数(预处理)
描述 给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=10000)并按从大到小的顺序排列. 输入 ...
- 无法访问部署在linux上的Tomcat服务器解决方案
笔者使用环境:CentOS 6.4 Windows7 tomcat7 主要原因是linux开启了防火墙,有两种解决方案,一种是关闭防火墙,另外一种是开放所要访问的端口 1.关闭防火墙(非常不建议) ...
- 如何在64位WIN7旗舰版下安装SQL2000
1>找到安装包下面的“DEVELOPER”或“ENTERPRISE”等下的X86\SETUP下的“SETUPSQL.EXE”,在安装前右键单击这个文 件, 1.1 打开“兼容性”标签,兼容模式选 ...
- springmvc中Controller方法的返回值
1.1 返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. 1.2 返回void 在controller方法形参 ...
- xmlhttp
File an issue about the selected textFile an issue about the selected text XMLHttpRequest Living Sta ...