题意:
给你n个城市的坐标,和m个基站的坐标,然后有t条路,给你起点和终点,求从起点到终点的过程中基站变化多少次,注意每次都选取最近的点作为基站。
题解说是什么什么图,其实啊按照代码来看就是一个分治加递归
#include"stdio.h"
#include"string.h"
#include"math.h"
#define N 51
struct node
{
double x,y;
}A[N],B[N];
int n,m;
double dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int min(node x)
{
int i,j;
double ans=0;
j=1;ans=1<<30;
for(i=1;i<=m;i++)
{
double t;
t=dis(x,B[i]);
if(ans>t)
{
ans=t;j=i;
}
}
return j;
}
int fun(node x,node y)
{
int a,b;
a=min(x);
b=min(y);
if(a==b)return 0;
if(sqrt(dis(x,y))<1e-7)return 1;
node t;
t.x=(x.x+y.x)/2.0;
t.y=(x.y+y.y)/2.0;
return fun(x,t)+fun(t,y);
}
int main()
{
int i;
int a,b;
while(scanf("%d%d",&n,&m)!=-1)
{
for(i=1;i

该博客探讨了一道HDU 4643的竞赛题目,涉及利用分治和递归策略来解决城市间移动时基站计数的变化。题目给出n个城市和m个基站的坐标,以及t条道路的起点和终点,任务是计算从起点到终点过程中基站的切换次数,每次移动选择最近的基站。博主分析了题目的图论背景,并通过代码展示了分治与递归的实现方法。
&spm=1001.2101.3001.5002&articleId=9818141&d=1&t=3&u=05ca9cd361a242db93f82efe2a1e1c03)
807

被折叠的 条评论
为什么被折叠?



