poj3178 Roping the Field (计算几何 + dp)
Roping the Field
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 858 | Accepted: 250 |
Description
There is one complication: FJ's field is not completely usable. Some evil aliens have created a total of G (0 <= G <= 100) grain circles in the field, all of radius R (1 <= R <= 100,000). FJ is afraid to upset the aliens, and therefore doesn't want the ropes to pass through, or even touch the very edge of a grain circle. Note that although the centers of all the circles are contained within the field, a wide radius may make it extend outside of the field, and both fences and fence posts may be within a grain circle.
Given the locations of the fence posts and the centers of the circles, determine the maximum number of ropes that FJ can use to create his field web.
FJ's fence pots and the circle centers all have integer coordinates X and Y each of which is in the range 0..1,000,000.
Input
Lines 2..N+1: Each line contains two space-separated integers that are the X,Y position of a fence post on the boundary of FJ's field.
Lines N+2..N+G+1: Each line contains two space-separated integers that are the X,Y position of a circle's center inside FJ's field.
Output
Sample Input
5 3 1
6 10
10 7
9 1
2 0
0 3
2 2
5 6
8 3
Sample Output
1
Hint
A pentagonal field, in which all possible ropes are blocked by three grain circles, except for the rope between fenceposts 2 and 4.
题意:
- 连线不能穿过任意一个圆,也不能与圆相切;
- 连线不能在中途相交,同一个点可以连多条线;
- 相邻的两个点不能连线(第一个点和第 n 个点是相邻的)。
思路:
首先在不考虑相交的情况下预处理出哪两个点可以连线,然后dp;
dp[i][j] 表示第 i 个点到第 j 个点最多可连多少条线,dp[i][j] = max(dp[i][k] + dp[k][j] + cnc[i][j], dp[i][j]);
其中 i < k < j;cnc[i][j] 表示 i , j 能否连线,能则为1,否则为0;
代码:
#include<map>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cctype>
#include<cfloat>
#include<cstdio>
#include<memory>
#include<string>
#include<vector>
#include<cassert>
#include<csignal>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#define LL long long
#define PB push_back
#define MAXN 171
#define RPT(I,L,R) for(int I=L;I<R;++I)
#define TPR(I,R,L) for(int I=R;I>=L;--I)
using namespace std;
template<class T> bool Umx(T &A,const T &B)
{
return B>A?A=B,1:0;
}
template<class T> bool Umn(T &A,const T &B)
{
return B<A?A=B,1:0;
}
const int inf=~0u>>2; int n,m,i,j,k;
LL r;
bool cnc[MAXN][MAXN];
int f[MAXN][MAXN]; struct point
{
LL x,y;
bool operator < (const point &T) const
{
return this->y<T.y || (this->y==T.y && this->x<T.x);
}
void read()
{
scanf("%I64d%I64d",&x,&y);
}
} p[MAXN],c[MAXN]; inline LL sqr(LL X)
{
return X*X;
}
inline LL dot(point A,point B,point O)
{
return (A.x-O.x)*(B.x-O.x)+(A.y-O.y)*(B.y-O.y);
}
inline LL cross(point A,point B)
{
return A.x*B.y-B.x*A.y;
}
inline LL cross(point A,point B,point O)
{
return (A.x-O.x)*(B.y-O.y)-(B.x-O.x)*(A.y-O.y);
}
inline LL dist2(point A,point B)
{
return sqr(A.x-B.x)+sqr(A.y-B.y);
} struct cmp
{
point O;
cmp(const point &OO):O(OO) {}
bool operator()(const point &A,const point &B)
{
return cross(A,B,O)>0;
}
}; void init()
{
memset(f,-1,sizeof f);
scanf("%d%d%d",&n,&m,&r);
RPT(i,0,n) p[i].read();
RPT(i,0,m) c[i].read();
sort(p,p+n);
sort(p+1,p+n,cmp(p[0]));
} bool CrsCcl(point A,point B,point O)
{
if (sqr(r)>=min(dist2(O,A),dist2(O,B))) return true;
if (dot(B,O,A)<0ll || dot(A,O,B)<0ll) return false;
return (double)r*r*dist2(A,B)>=(double)cross(A,B,O)*cross(A,B,O);
} void Deal_Cnc()
{
memset(cnc,false,sizeof cnc);
RPT(i,0,n)
RPT(j,i+2,n)
if (!(i==0 && j==n-1))
{
cnc[i][j]=cnc[j][i]=true;
RPT(k,0,n)
if (CrsCcl(p[i],p[j],c[k]))
{
cnc[i][j]=cnc[j][i]=false;
break;
}
}
} int DP(int L,int R)
{
if (f[L][R]>0) return f[L][R];
if (R-L<2) return f[L][R]=0;
else if (R-L==2) return cnc[L][R];
int res=0;
RPT(i,L+1,R) Umx(res,DP(L,i)+DP(i,R));
return f[L][R]=res+cnc[L][R];
} int main()
{
init();
Deal_Cnc();
printf("%d\n",DP(0,n-1));
return 0;
}
poj3178 Roping the Field (计算几何 + dp)的更多相关文章
- BZOJ 1719--[Usaco2006 Jan] Roping the Field 麦田巨画(几何&区间dp)
1719: [Usaco2006 Jan] Roping the Field 麦田巨画 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 82 Solved ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- POJ3178 计算几何+DP
//一些点一些圆,过圆不能连线,相邻点不能连线,问最多连几条线 //计算几何模板+区间dp //关键是判断圆和线段是否相交 #include <cstdio> #include <c ...
- 『HGOI 20190917』Cruise 题解 (计算几何+DP)
题目概述 在平面直角坐标系的第$1$象限和第$4$象限有$n$个点,其中第$i$个点的坐标为$(x_i,y_i)$,有一个权值$p_i$ 从原点$O(0,0)$出发,不重复的经过一些点,最终走到原点, ...
- HDU 4562 守护雅典娜 (计算几何+DP)
守护雅典娜 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- Code Chef MINPOLY(计算几何+dp)
题面 传送门 题解 我们枚举这个凸多边形\(y\)坐标最小的点\(p_i\),然后对于所有\(y\)坐标大于等于它的点极角排序 我们预处理出\(s_{j,k}\)表示三角形\(p_i,p_j,p_k\ ...
- bzoj 3778: 共鸣【计算几何+dp】
枚举起点,然后设f[i][j]为上凸壳上一个点是i当前点是j的最大面积,g是下凸壳,然后合并的时候枚举结束点t合并上下凸壳即可 这样的好处是每次转移都是往凸多边形里加一个三角形(s,i,j),所以判断 ...
- POJ 3254 Corn Fields:网格密铺类 状压dp
题目链接:http://poj.org/problem?id=3254 题意: 给你一片n*m的耕地,你可以在上面种玉米.但是其中有一些地方是荒芜的,不能种植.并且种植玉米的地方不能相邻.问你在这片地 ...
- hdu 1081 dp问题:最大子矩阵和
题目链接 题意:给你一个n*n矩阵,求这个矩阵的最大子矩阵和 #include<iostream> #include<cstdio> #include<string.h& ...
随机推荐
- Burger King使用RayOnSpark进行基于实时情景特征的快餐食品推荐
作者:Luyang Wang, Kai Huang, Jiao Wang, Shengsheng Huang, Jason Dai 基于深度学习的推荐模型已广泛应用于各种电商平台中,为用户提供推荐.目 ...
- 快速上手开发——JFinal配置(全步骤图文解析)
摘要: 因为发现官网上只有Eclipse的配置文档,就写了这篇基于IDEA+maven的配置流程.本文使用安装了maven插件的IDEA进行配置,为了照顾IDEA新手,几乎每个步骤都截了图. 环境说明 ...
- gRPC-go 入门(1):Hello World
摘要 在这篇文章中,主要是跟你介绍一下gRPC这个东西. 然后,我会创建一个简单的练习项目,作为gRPC的Hello World项目. 在这个项目中,只有很简单的一个RPC函数,用于说明gRPC的工作 ...
- Combine 框架,从0到1 —— 5.Combine 提供的发布者(Publishers)
本文首发于 Ficow Shen's Blog,原文地址: Combine 框架,从0到1 -- 5.Combine 提供的发布者(Publishers). 内容概览 前言 Just Future D ...
- 手把手教你基于CentOS8搭建微信订阅号后台服务(一)
一.准备域名并完成解析 关于域名,我买的是阿里的一个1元/年的廉价域名,同时国内域名都需要备案,当时在这里耽搁了挺久的. 域名解析的话,在阿里云官方帮助文档里有.传送门:https://help.al ...
- 每日爬虫JS小逆之5分钟旅游网MD5一锅端
来吧骚年,每天花5分钟锻炼一下自己的JS调试也是极好的,对后期调试滑块验证码还原.拖动很有帮助,坚持下去,我们能赢.建议亲自试试哦,如果对大家有帮助的话不妨关注一下知识图谱与大数据公众号,当然不关注也 ...
- 报表和仪表板在线设计器Stimulsoft Designer 最新版发布
Stimulsoft Designer是统一的Stimulsoft框架的一部分,该框架包括用于生成报表和分析数据的引擎.报表设计器和查看器. 您可以在计算机上创建报表,继续使用在线设计器在云中对其进行 ...
- Linux I2C驱动框架
Linux的I2C体系结构分为3个组成部分: I2C核心( i2c-core.c ): I2C核心提供了I2C总线驱动和设备驱动的注册.注销方法.I2C通信方法("algorithm&qu ...
- 解Bug之路-记一次线上请求偶尔变慢的排查
解Bug之路-记一次线上请求偶尔变慢的排查 前言 最近解决了个比较棘手的问题,由于排查过程挺有意思,于是就以此为素材写出了本篇文章. Bug现场 这是一个偶发的性能问题.在每天几百万比交易请求中,平均 ...
- C# Socket TCP发送图片与接收图片
如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! ! --------------------------- ...