BZOJ 3199 escape
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3199
题意:给出n个点。对于平面上任意一点p,p到n个点中的哪个点的距离最近我们就称p就被哪个点控制。有可能p被多个点同时控制(距离相等的时候)。给出一个矩形框(0,0,X,Y)以及框内一点q。从q到达矩形框上的途中,最少被多少个点控制过?
思路:n个点中的每个点有一个控制区域。某个点和其他点中垂线组成的半平面交就是这个区域。这个可以用凸包计算。这里是一个nlogn求凸包的算法,第二次遇到这个算法,第一次是:
http://www.cnblogs.com/jianglangcaijin/archive/2013/03/07/2947784.html
然后就是有公共边的连边求最短路。
point S,p[N];
struct Tline
{
point p1,p2;
int id;
double ang;
Tline(){}
Tline(point _p1,point _p2,int _id)
{
p1=_p1;
p2=_p2;
ang=atan2(p2.y-p1.y,p2.x-p1.x);
id=_id;
}
}L[N];
point crossPoint(Tline l1,Tline l2)
{
double ta=(l1.p2-l2.p1)*(l1.p1-l2.p1);
double tb=(l1.p1-l2.p2)*(l1.p2-l2.p2);
return (l2.p1*tb+l2.p2*ta)/(ta+tb);
}
double xx,yy;
int n,tot;
double dist(const point &a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
int cmp(const Tline &a,const Tline &b)
{
if(sgn(a.ang-b.ang)==0) return sgn((a.p1-b.p1)*(b.p2-b.p1))<0;
return sgn(a.ang-b.ang)<0;
}
int onleft(const Tline &l1,const Tline &l2,const Tline &l3)
{
point tp=crossPoint(l1,l2);
return sgn((l3.p2-l3.p1)*(tp-l3.p1))>=0;
}
vector<int> g[N];
void hpi(int x)
{
sort(L+1,L+1+tot,cmp);
int i,tp=1;
for(i=2;i<=tot;i++) if(sgn(L[i].ang-L[i-1].ang)!=0) L[++tp]=L[i];
tot=tp;
int front=1,rear=1;
int Q[N];
Q[1]=1;
for(i=2;i<=tot;i++)
{
while(front<rear&&!onleft(L[Q[rear-1]],L[Q[rear]],L[i]))rear--;
while(front<rear&&!onleft(L[Q[front]],L[Q[front+1]],L[i]))front++;
Q[++rear]=i;
}
while(front<rear&&!onleft(L[Q[rear-1]],L[Q[rear]],L[Q[front]]))rear--;
while(front<rear&&!onleft(L[Q[front]],L[Q[front+1]],L[Q[rear]]))front++;
if(rear-front<2)return;
for(i=front;i<=rear;i++)
{
int y=L[Q[i]].id;
g[x].pb(y);
}
}
void work(int x)
{
tot=0;
L[++tot]=Tline(point(0,0), point(xx,0), n+1);
L[++tot]=Tline(point(xx,0), point(xx,yy),n+1);
L[++tot]=Tline(point(xx,yy),point(0,yy), n+1);
L[++tot]=Tline(point(0,yy), point(0,0), n+1);
int i;
for(i=1;i<=n;i++) if(i!=x)
{
point S=(p[i]+p[x])/2;
point d=(p[i]-p[x]).zhuanNi(PI/2);
point T=S+d;
L[++tot]=Tline(S,T,i);
}
hpi(x);
}
int bfs(int st)
{
queue<int> Q;
Q.push(st);
int i,dis[N],visit[N];
for(i=1;i<=n+1;i++) dis[i]=1e9,visit[i]=0;
dis[st]=0;
visit[st]=1;
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for(i=0;i<SZ(g[u]);i++)
{
int v=g[u][i];
if(!visit[v])
{
visit[v]=1;
dis[v]=dis[u]+1;
Q.push(v);
}
}
}
return dis[n+1];
}
int main()
{
int T=getInt();
while(T--)
{
n=getInt();
xx=getInt(),yy=getInt();
S.get();
int i;
for(i=1;i<=n;i++)p[i].get(),g[i].clear();
for(i=1;i<=n;i++) work(i);
int st=1;
double tmp=dist(p[1]-S);
for(i=2;i<=n;i++) if(dist(p[i]-S)<tmp)
{
tmp=dist(p[i]-S);
st=i;
}
printf("%d\n",bfs(st));
}
return 0;
}
BZOJ 3199 escape的更多相关文章
- BZOJ 1340: [Baltic2007]Escape逃跑问题
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 285 Solved: 133[Submit] ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 3940: [Usaco2015 Feb]Censoring
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 367 Solved: 173[Subm ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
- bzoj 4610 Ceiling Functi
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
- BZOJ 题目整理
bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...
随机推荐
- -XX:+PrintGCTimeStamps 打印CG发生的时间戳
-XX:+PrintGCTimeStamps –打印CG发生的时间戳 –[GC[DefNew: 4416K->0K(4928K), 0.0001897 secs] 4790K->374 ...
- XStream xml转java对象
1:引入jar qn <dependency> <groupId>xstream</groupId> <artifactId>xstream</a ...
- Parse_ini_file
parse_ini_file() 函数解析一个配置文件,并以数组的形式返回其中的设置. 注释:本函数可以用来读取你自己的应用程序的配置文件.本函数与 php.ini 文件没有关系,该文件在运行脚本时就 ...
- android 学习随笔二十九(自定义监听 )
package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...
- MySQL OnlineDDL
参考资料: http://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html http://www.mysqlperfo ...
- scala的apply方法
package com.test.scala.test /** * apply 方法 */ object ApplyTest { def main(args: Array[String]): Unit ...
- linux下的module_param()解释【转】
转自:http://blog.csdn.net/wavemcu/article/details/7762133 版权声明:本文为博主原创文章,未经博主允许不得转载. ***************** ...
- 6.1:SportStore:一个真实的应用
之前的小例子让我们演示了AngularJS的一些特性,但他们缺少上下文.要解决这个问题,作者要创建一个简单单真实的电子商务应用. 作者将创建一个在线产品分类,客户可以通过分类和页面浏览,一个购物车用户 ...
- [转]System.Reflection.AssemblySignatureKeyAttribute
转自:http://www.cnblogs.com/ego/p/3321122.html 错误: Could not load type 'System.Reflection.AssemblySign ...
- frameset子窗口获取父窗口失败原因?
报错信息: arrow.html:44 Uncaught SecurityError: Blocked a frame with origin "null" from access ...