HDU-4643-GSM(DFS)
base station when moving on the train. Xiao Ming would like to know how many times the base station will change from city A to city B.
Now, the problem is simplified. We assume the route of train is straight, and the mobile phone will receive the signal from the nearest base station.
0<=y<=1000, both x and y is integer).Then there is a number : K, the next, there are K queries, for each query, each line, there are two numbers: a, b.
4 4
0 2
1 3
1 0
2 0
1 2
1 1
2 2
2 1
4
1 2
1 3
1 4
3 4
0
1
2
1HintThe train way from a to b will not cross the point with the same distance from more than 2 base stations.
(For the distance d1 and d2, if fabs(d1-d2)<1e-7, we think d1 == d2).
And every city exactly receive signal from just one base station.
思路:每次获取中点的近期的基站的id,id跟哪边不一样就往哪边递归查找。
#include <stdio.h>
#define INF 99999999 int n,m,ans;
bool vis[50];
double sx[50],sy[50],ex[50],ey[50]; int get(double x,double y)//获取离该点近期的基站
{
double mn=INF;
int id,i; for(i=0;i<m;i++)
{
if((x-ex[i])*(x-ex[i])+(y-ey[i])*(y-ey[i])<mn)
{
mn=(x-ex[i])*(x-ex[i])+(y-ey[i])*(y-ey[i]);
id=i;
}
} return id;
} void dfs(int l,int r,double lx,double ly,double rx,double ry)//递归查找,每次获取中点的近期的基站的id,id跟哪边不一样就往哪边找。 {
if((lx-rx)*(lx-rx)+(ly-ry)*(ly-ry)<1e-14) return; double x=(lx+rx)/2.0;
double y=(ly+ry)/2.0; int id=get(x,y); if(!vis[id])
{
vis[id]=1;
ans++;
} if(id!=l) dfs(l,id,lx,ly,x,y); if(id!=r) dfs(id,r,x,y,rx,ry);
} int main()
{
int i,q,id1,id2;
int from,to; while(~scanf("%d%d",&n,&m))
{
for(i=0;i<n;i++) scanf("%lf%lf",&sx[i],&sy[i]); for(i=0;i<m;i++) scanf("%lf%lf",&ex[i],&ey[i]); scanf("%d",&q); while(q--)
{
scanf("%d%d",&from,&to); id1=get(sx[from-1],sy[from-1]);
id2=get(sx[to-1],sy[to-1]); if(id1==id2) printf("0\n");
else
{
for(i=0;i<m;i++) vis[i]=0;
vis[id1]=1;
vis[id2]=1;
ans=1;
dfs(id1,id2,sx[from-1],sy[from-1],sx[to-1],sy[to-1]);
printf("%d\n",ans);
}
}
}
}
HDU-4643-GSM(DFS)的更多相关文章
- hdu 4643 GSM 计算几何 - 点线关系
/* hdu 4643 GSM 计算几何 - 点线关系 N个城市,任意两个城市之间都有沿他们之间直线的铁路 M个基站 问从城市A到城市B需要切换几次基站 当从基站a切换到基站b时,切换的地点就是ab的 ...
- HDU 4643 GSM 算术几何
当火车处在换基站的临界点时,它到某两基站的距离相等.因此换基站的位置一定在某两个基站的中垂线上, 我们预处理出任意两基站之间的中垂线,对于每次询问,求询问线段与所有中垂线的交点. 检验这些交点是否满足 ...
- HDU 4643 GSM (2013多校5 1001题 计算几何)
GSM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...
- hdu 4643 GSM(暴力)
GSM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submis ...
- HDU 4643 GSM 简单计算几何
今天比赛的时候略坑, admin告诉我询问Q的个数不超过n^2, 赛后敲了个 O(Q*m^3)的复杂度,但这个复杂度常数比较低,可能在除以个小常数, 300ms过了,真心无语,数据应该水了吧,比赛的时 ...
- HDU 4643 GSM 暑期多校联合训练第五场 1001
点击打开链接 我就不说官方题解有多坑了 V图那么高端的玩意儿 被精度坑粗翔了 AC前 AC后 简直不敢相信 只能怪自己没注意题目For the distance d1 and d2, if fabs( ...
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- hdu 1175 连连看 DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...
随机推荐
- ORM之创建数据库
ORM之创建数据库 样板:创建表名为UserInfo的表,表的主键可自行写,Django的ORM也可自行创建. from django.db import models class UserInfo( ...
- 杭电 1862 EXCEL排序(sort+结构体)
Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=100000 ...
- jQuery实现上传进度条效果
效果:(点击上传按钮) See the Pen pjGNJr by moyu (@MoYu1991) on CodePen. html代码: <!DOCTYPE html> <h ...
- windows10开启内置ubuntu系统,使用xshell连接
windows安装配置ubuntu系统内置子系统 官方文档:https://docs.microsoft.com/zh-cn/windows/wsl/about https://www.jianshu ...
- Error connecting to database: No such file or directory
标签:Error connecting to database: No such file or directory 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明 ...
- [luoguP1058] 立体图(超级大模拟(¬︿̫̿¬☆))
传送门 看到题后整个人成了mengbier 但是仔细分析一下就很简单了,先确定好输出的图的长和宽. 然后从输入的矩形的左上角的最下面的开始填充,顺序是从下到上,从左到右,从后往前. 填充的时候直接覆盖 ...
- [K/3Cloud] 创建一个单据转换插件
概念: 创建一个业务单据转换插件,在单据转换的各个时点干预单据转换的相关逻辑控制. 示例: 新建一个类,继承自单据转换插件基类Kingdee.BOS.Core.Metadata.ConvertElem ...
- eclipse安装Aptana 插件,并设置使之能提示css,js,html,帮助编写代码
在Eclipse 4.2 上安装 Aptana 3.2遇到的错误 就是找不到什么文件来着,我在装maven的时候也遇到了. 烦人... (这文章是我还在用eclipse的时候,为了编写js代码的时候提 ...
- 【中文排序】mysql order by 中文排序
1. 在MySQL中,我们经常会对一个字段进行排序查询,但进行中文排序和查找的时候,对汉字的排序和查找结果往往都是错误的. 这种情况在MySQL的很多版本中都存在. 如果这个问题不解决,那么MySQL ...
- 使用 docker 安装 OpenVAS 漏洞扫描软件
https://blog.csdn.net/freewebsys/article/details/78804624