1719: [Usaco2006 Jan] Roping the Field 麦田巨画

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 82  Solved: 26
[Submit][Status][Discuss]

Description

Farmer John is quite the nature artist: he often constructs large works of art on his farm. Today, FJ wants to construct a giant "field web". FJ's field is large convex polygon with fences along the boundary and fence posts at each of the N corners (1 <= N <= 150). To construct his field web, FJ wants to run as many ropes as possible in straight lines between pairs of non-adjacent fence posts such that no two ropes cross. 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 posts and the circle centers all have integer coordinates X and Y each of which is in the range 0..1,000,000.

    约翰真是一个自然派艺术大师,他常常在他的田地上创作一些巨大的艺术杰作.今天,他想在麦田上创作一幅由绳索构成的巨画.他的麦田是一个多边形,由N(1≤N≤150)个篱笆桩和之间的篱笆围成.为了创作他的巨画,他打算用尽量多的数量的绳索,笔直地连接两个不相邻的篱笆桩.但是为了画作的优美,任意两根绳索不得交叉.
    约翰有一个难处:一些邪恶的外星人在他的麦田上整出了G(O≤G≤100)个怪圈.这些怪圈都有一定的半径R(1≤R≤100000).他不敢惹外星人,所以不想有任何绳索通过这些怪圈,即使碰到怪圈的边际也不行.这些怪圈的圆心都在麦田之内,但一些怪圈可能有部分在麦田之外.一些篱笆或者篱笆桩都有可能在某一个怪圈里.
    给出篱笆桩和怪圈的坐标,计算最多的绳索数.所有的坐标都是[0,10^61内的整数.

Input

* Line 1: Three space-separated integers: N, G, and R * 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.

    第1行输入三个整数N,G,R.接下来N行每行输入两个整数表示篱笆桩的坐标.接下来G行每行输入两个整数表示一个怪圈的圆心坐标.

Output

* Line 1: A single integer that is the largest number of ropes FJ can use for his artistic creation.

    最多的线索数.

Sample Input

5 3 1
6 10
10 7
9 1
2 0
0 3
2 2
5 6
8 3

INPUT DETAILS:

A pentagonal field, in which all possible ropes are blocked by three
grain circles, except for the rope between fenceposts 2 and 4.

Sample Output

1

HINT

除了篱笆桩2和4之间可以连接绳索,其余均会经过怪圈

 

题目链接:

    http://www.lydsy.com/JudgeOnline/problem.php?id=1719

Solution

  首先看到题目应该是几何题无误(假装很有道理
  看到n<=150感觉似乎暴力也能过。。想想边数最多也只有22500条。。。
  于是这时候应该马上想到先预处理每条边是否可以连。。。
  直接算圆和线段的交点?感觉应该可以但是似乎不怎么好写。。。
  考虑题意。。只要线段有部分含于圆内就不能连。。而这个“部分”可以直接认为是线段上与圆心最近的点。。
  于是这个预处理就转化成了求点到线段的最小距离。。这个套套公式就好。。感觉三分也可以但是tle了(可能是我写炸了。。
  预处理完之后,考虑怎么求答案。。。
  要求线段之间不可以相交。。。。
  说白了就是不能有1->4 , 2->5这样的线段同时存在。。考虑DP。。那肯定只能区间DP了。。
  n<=150的话O(n^3)还是很轻松的吧

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#define N 20050
#define ept 1e-6
using namespace std;
int n,m;
double R;
struct P{
double x,y;
}a[200],b[200];
int f[200][200];
bool vis[200][200];
double dis(P u,P v){
return sqrt((u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));
}
double DIS(P u,P v,P w) {
double space=0;
double a,b,c;
a=dis(u,v);
b=dis(u,w);
c=dis(v,w);
if(c<=ept||b<=ept) {
space=0;
return space;
}
if(a<=ept){
space=b;
return space;
}
if(c*c>=a*a+b*b){
space=b;
return space;
}
if(b*b>=a*a+c*c) {
space=c;
return space;
}
double p=(a+b+c)/2;
double s=sqrt(p*(p-a)*(p-b)*(p-c));
space=2*s/a;
return space;
}
bool judge(P u,P v,P w){
double d1=DIS(u,v,w);
if(d1>R) return 0;
return 1;
}
bool check(P u,P v){
for(int i=1;i<=m;i++)
if(judge(u,v,b[i])) return 0;
return 1;
}
int main(){
scanf("%d%d%lf",&n,&m,&R);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
for(int i=1;i<=m;i++)
scanf("%lf%lf",&b[i].x,&b[i].y);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==j) continue;
vis[i][j]=check(a[i],a[j]);
}
}
for(int len=3;len<=n;len++){
for(int i=1;i<=n-len+1;i++){
for(int j=i;j<=i+len-1;j++)
f[i][i+len-1]=max(f[i][i+len-1],f[i][j]+f[j][i+len-1]);
if(vis[i][i+len-1]&&(i!=1||i+len-1!=n))
f[i][i+len-1]++;
}
}
printf("%d\n",f[1][n]);
return 0;
}

  

  

This passage is made by Iscream-2001.

BZOJ 1719--[Usaco2006 Jan] Roping the Field 麦田巨画(几何&区间dp)的更多相关文章

  1. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  2. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  3. [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

    [BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...

  4. BZOJ——1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1720 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1 ...

  5. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径

    Description 给出一个无向图,求将他构造成双连通图所需加的最少边数. Sol Tarjan求割边+缩点. 求出割边,然后缩点. 将双连通分量缩成一个点,然后重建图,建出来的就是一棵树,因为每 ...

  6. bzoj:1656 [Usaco2006 Jan] The Grove 树木

    Description The pasture contains a small, contiguous grove of trees that has no 'holes' in the middl ...

  7. bzoj:1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会

    Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in ...

  8. BZOJ 1656 [Usaco2006 Jan] The Grove 树木:bfs【射线法】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1656 题意: 给你一个n*m的地图,'.'表示空地,'X'表示树林,'*'表示起点. 所有 ...

  9. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】

    几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...

随机推荐

  1. cannot convert from 'wchar_t *' to 'char *' 问题

    MFC中使用unicode 会导致cstring之间的转换变的很复杂 经常遇到这样的错误cannot convert from 'wchar_t *' to 'char *' 强制转换成wchar_t ...

  2. 只有自己看的懂的vue 二叉树的3级联动

    我是在vue做的数据 actions mutations state index页面获取值 传递给子页面 子页面的操作 <template> <div class='cascade_ ...

  3. python while语句写法

    count=5 while count>0: print 'i love python' count=count-1 else: print 'over'

  4. 如何处理好前后端分离的 API 问题(转载自知乎)

    9 个月前 API 都搞不好,还怎么当程序员?如果 API 设计只是后台的活,为什么还需要前端工程师. 作为一个程序员,我讨厌那些没有文档的库.我们就好像在操纵一个黑盒一样,预期不了它的正常行为是什么 ...

  5. Maven系列(十)发布自己的项目到 Maven 中央仓库

    Maven 发布自己的项目到 Maven 中央仓库 可能很多人都在用 Maven 仓库,但是如果要问怎么发布项目到中央仓库,估计很多人都不知道了,下面本篇文章带大家往中央仓库发布一个自己的 Maven ...

  6. bitnami redmine svn配置

    采用bitnami 方案安装redmine svn服务器端会自己进行安装 1.创建版本库 首先进入remine安装目录的subversion/bin目录,例如我的安装目录是“/opt/redmine/ ...

  7. [转载红鱼儿]Delphi XE7 update1进步太大了

    写以下的文字是怀着无比兴奋的心情写的,急于同朋友们分享XE7的进步! 1.更新的bug列表并不全 通过bug修正列表及发布的消息,可以看到up1修正了很多bug,正如我所说,有些bug并没有写到发布的 ...

  8. 2018.09.25 codeforces1053E. Euler tour(并查集+st表+模拟)

    传送门 毒瘤细节题. 首先考虑不合法的情况. 先把相同的值配对,这样就构成了一些区间. 那么如果这些区间有相交的话,就不合法了. 如何判断?DZYO安利了一波st表,我觉得很不错. 接着考虑两个相同的 ...

  9. linux环境下的mysql,httpd以及与宿主机的调试问题总结

    1. 首先www服务器,在宿主主机浏览器无法访问? (1)修改linux的防火墙,允许宿主主机ip访问即可. (2)关闭防火墙,即可访问. service iptables stop; 2. mysq ...

  10. Maven发布和管理项目

    1 什么是Maven? 如果没有Maven,你可能不得不经历下面的过程: 1 如果使用了spring,去spring的官网下载jar包:如果使用hibernate,去hibernate的官网下载Jar ...