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. RabbitMQ消费端ACK与重回队列机制,TTL,死信队列详解(十一)

    消费端的手工ACK和NACK 消费端进行消费的时候,如果由于业务异常我们可以进行日志的记录,然后进行补偿. 如果由于服务器宕机等严重问题,那么我们就需要手工进行ACK保障消费端成功. 消费端重回队列 ...

  2. 10 Django与Ajax

    知识预览 1. Ajax 2. 文件上传 Ajax Ajax简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Javascript和XML”.即使用J ...

  3. 二十四、python中sys模块

    '''1.sys.argv:命令行参数List,第一个元素是程序本身路径''' import sys print (sys.argv)-------------------------------[' ...

  4. 架构-层-DAL:DAL

    ylbtech-架构-层-DAL:DAL DAL是数据访问层的英文缩写,即为数据访问层(Data Access Layer).其功能主要是负责数据库的访问.简单地说就是实现对数据表的Select(查询 ...

  5. sc 使用了配置中心后,如何设置远程和本地配置的优先级

    在 spring 中,如何获取一个 key 的值? applicationContext.getEnvironment().getProperty("swagger.show") ...

  6. 测开之路一百一十:bootstrap图片

    bootstrap图片 引入bootstrap 原版的图片 bootstrap处理后的: 圆角.圆形.缩略图 自适应窗口

  7. 测开之路九十八:js变量和语句

    这里为了方便调试,在jsbin网站上面编写js脚本:https://jsbin.com/?js,console 可以点击增加/减少对应展示分页,Console为控制台部分,Output为页面部分 变量 ...

  8. JsonDatetime

    ToDatetime public DateTime JsonDateTimeConvert(string time) { //try //{ if (String.IsNullOrEmpty(tim ...

  9. mysql 添加外键报错:

    1.报错信息 Cannot add or update a child row: a foreign key constraint fails 2.原因分析 [1]字段的数据类型 父表: 子表: 以上 ...

  10. auto_ptr与shared_ptr

    注: 从c++11开始, auto_ptr已经被标记为弃用, 常见的替代品为shared_ptr shared_ptr的不同之处在于引用计数, 在复制(或赋值)时不会像auto_ptr那样直接转移所有 ...