题意:
给你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