GSM

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 569    Accepted Submission(s): 182

Problem Description
Xiao Ming is traveling around several cities by train. And the time on the train is very boring, so Xiao Ming will use the mobile Internet. We all know that mobile phone receives the signal from base station and it will change the 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. 
 
Input
Multiple cases. For each case, The first line: N(3<=N<=50) - the number of cities, M(2<=M<=50) - the number of base stations. Then there are N cities with coordinates of (x, y) and M base stations with coordinates of (x, y) - (0<=x<=1000, 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.
 
Output
For each query, tell Xiao Ming how many times the base station will change from city a to city b.
 
Sample Input
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
 
Sample Output
0
1
2
1

Hint

The 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.

 
Source
 
zhuyuanchen520
 
 
 
 
想法:
  
  假设是a  city  到 b  city;
 
  首先先找到离起点最近的电台!
 
  然后以这个点为辅助点去找下一个点(而下一个点该怎么确定呢??);
 
  我们可以这样做:枚举其他所有的电台,与辅助点连接做中垂线,交于线段一点,枚举完后找到最靠左边的那个点
 
  并把这个点叫做关键点,之后如此重复,不断的更新这个关键点,每更新一次次数ans++,直到这个关键点移出了 b 点!!
 
 
 
  

 #include<stdio.h>
#include<string.h>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define pi acos(-1.0)
#define eps 1e-7
#define oo 99999998
struct point
{
double x,y;
point(double _x = 0.0,double _y = 0.0)
{
x =_x;
y =_y;
}
point operator -(const point &b)const
{
return point(x - b.x, y - b.y);
}
point operator +(const point &b)const
{
return point(x +b.x, y + b.y);
}
point operator |(const double &b)const
{
return point(x*b, y*b);
}
double operator ^(const point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const point &b)const
{
return x*b.x + y*b.y;
} void input()
{
scanf("%lf%lf",&x,&y);
}
}; int dcmp(double a)
{
if(fabs(a)<eps)return ;
if(a>)return ;
else return -;
} double len(point a)
{
return sqrt(a*a);
} double Angle(point a,point b)
{
double ans=acos((a*b)/len(a)/len(b));
return ans;
} point getjiaodian(point p,point v,point q,point w)
{
point u;
u=p-q;
double t=(w^u)/(v^w);
v.x=t*v.x;v.y=t*v.y;
return p+v;
} int n,m,id,x,y;
int v[];
point p1[],p2[];//p1为city p2为电台
point qiujiaodian(point touying,point shit)
{
int i;
point ans=p1[y]+(p1[y]-p1[x]),xx;//ans用来更新投影
xx=p1[y]-p1[x];//线段的方向向量
for(i=;i<=m;i++)
{
if(v[i])continue;
point u=shit-p2[i],w,qq;
if(dcmp(u*xx)==)continue;
qq=(shit+p2[i])|(0.5);
w.x=u.y,w.y=-u.x;
point jiao;
if(dcmp((qq-p1[x])^xx)==)jiao=qq;
else
jiao=getjiaodian(qq,w,touying,xx);
if(dcmp(len(touying-ans)-len(jiao-touying)-len(jiao-ans))==)
{
ans=jiao;
id=i;
}
}
return ans;
} int main()
{
int i,k; while(~scanf("%d%d",&n,&m))
{
for(i=;i<=n;i++)p1[i].input();
for(i=;i<=m;i++)p2[i].input();
scanf("%d",&k);
while(k--)
{
scanf("%d%d",&x,&y);
int ss,ee;//ss为距离x最近的点,ee为距离b最近的点!!
ss=ee=;
double min1,min2;
min1=min2=oo;
for(i=;i<=m;i++)
{
if(len(p2[i]-p1[x])<min1)
{
min1=len(p2[i]-p1[x]);
ss=i;
}
if(len(p2[i]-p1[y])<min2)
{
min2=len(p2[i]-p1[y]);
ee=i;
}
}
if(ss==ee){printf("0\n");continue;}
memset(v,,sizeof(v));
v[ss]=;//v[ee]=1;
point shit=p2[ss],touying=p1[x];
int cnt=;
while(dcmp(len(p1[x]-p1[y])-len(p1[x]-touying)-len(p1[y]-touying))==)
{
touying=qiujiaodian(touying,shit);
v[id]=;
shit=p2[id];
cnt++;
} printf("%d\n",cnt-);
}
}
return ;
}
 
 
 
 
 
 
 
 
 
 
 
·

hdu 4643 GSM(暴力)的更多相关文章

  1. hdu 4643 GSM 计算几何 - 点线关系

    /* hdu 4643 GSM 计算几何 - 点线关系 N个城市,任意两个城市之间都有沿他们之间直线的铁路 M个基站 问从城市A到城市B需要切换几次基站 当从基站a切换到基站b时,切换的地点就是ab的 ...

  2. HDU 4643 GSM 算术几何

    当火车处在换基站的临界点时,它到某两基站的距离相等.因此换基站的位置一定在某两个基站的中垂线上, 我们预处理出任意两基站之间的中垂线,对于每次询问,求询问线段与所有中垂线的交点. 检验这些交点是否满足 ...

  3. HDU 4643 GSM (2013多校5 1001题 计算几何)

    GSM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...

  4. HDU 4643 GSM 简单计算几何

    今天比赛的时候略坑, admin告诉我询问Q的个数不超过n^2, 赛后敲了个 O(Q*m^3)的复杂度,但这个复杂度常数比较低,可能在除以个小常数, 300ms过了,真心无语,数据应该水了吧,比赛的时 ...

  5. HDU 4643 GSM 暑期多校联合训练第五场 1001

    点击打开链接 我就不说官方题解有多坑了 V图那么高端的玩意儿 被精度坑粗翔了 AC前 AC后 简直不敢相信 只能怪自己没注意题目For the distance d1 and d2, if fabs( ...

  6. HDU 5510 Bazinga 暴力匹配加剪枝

    Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...

  7. HDU 5522 Numbers 暴力

    Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5522 ...

  8. hdu 5077 NAND(暴力打表)

    题目链接:hdu 5077 NAND 题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符.如今给定要求生成的8个字符.问 说Xiaoqiang最少要写多少行代码. ...

  9. hdu 5726 GCD 暴力倍增rmq

    GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...

随机推荐

  1. Hash算法原理以及HashCode深入理解

    Java中的Collection有两类,一类是List,一类是Set.List内的元素是有序的,元素可以重复.Set元素无序,但元素不可重复.要想保证元素不重复,两个元素是否重复应该依据什么来判断呢? ...

  2. 启用和配置 FILESTREAM

    2017/08/23 在开始使用 FILESTREAM 之前,必须在 SQL Server 数据库引擎实例中启用 FILESTREAM. 本主题说明了如何使用 SQL Server 配置管理器来启用 ...

  3. rpm安装软件时提示warning: *.rpm: Header V3 RSA/SHA256 Signature, keykey ID c105b9de

    在RedHat下有时候用rpm安装软件是会出现下面则中错误 1.安装时提示:warning: *.rpm: Header V3 RSA/SHA256 Signature, keykey ID c105 ...

  4. Jmeter之Switch Controller

    在测试过程中,各种不同的情况需要执行不同的操作,这个时候用if控制器比较麻烦,此时就可以使用Switch Controller代替. 一.界面显示 二.配置说明 1.名称:标识 2.注释:备注 3.S ...

  5. create-react-app 创建react应用环境变量(env)配置

    参考:https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables What other . ...

  6. ETROBOT——审题

    参加了比赛,但是总要理解比赛相关的东西,发现以前瞎写的东西有人看,并且还有挺多人看的,所以打算继续在这里面,做记录. 源: http://www.etrobo.jp/2018/gaiyou/intro ...

  7. 【USACO18JAN】MooTube

    原文链接:https://blog.csdn.net/Patrickpwq/article/details/86656456 给定一棵n个点的树(n=1e5),有边权, 两点间距离定义为两点路径上的 ...

  8. Tesseract5.0训练字库,提高OCR特殊场景识别率(一)

    0.目标 很多特殊场景,原生的字库识别率不高,这时候就需要根据需求自己训练字库生成traineddata文件. 一.前期准备工作 1.安装jdk   用于运行jTessBoxEditor 2.安装jT ...

  9. “希希敬敬对”队软件工程第九次作业-beta冲刺第一次随笔

    队名:  “希希敬敬对” 龙江腾(队长) 201810775001 杨希                   201810812008 何敬上 201810812004 今日讨论会议照片一张: 每个人 ...

  10. [Web 前端] 015 css 三种元素的介绍

    1. 块元素,内联元素,内联块元素 元素就是标签 布局中常用的有三种标签 块元素 内联元素 内联块元素 1.1 块元素 也称为行元素 布局中常用的标签,如 div.p.ul.li.h1~h6.dl.d ...