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. Ubuntu 14.04 DNS 丢失 | 中文输入法配置 (转载)

    1)彻底解决Ubuntu 14.04 重启后DNS配置丢失的问题: http://www.tuicool.com/articles/RVZn2y 2)Ubuntu 14.04中文输入法的安装   ht ...

  2. #1112-JSP生命周期

    JSP 生命周期 理解JSP底层功能的关键就是去理解它们所遵守的生命周期. JSP生命周期就是从创建到销毁的整个过程,类似于servlet生命周期,区别在于JSP生命周期还包括将JSP文件编译成ser ...

  3. CF704D Captain America

    http://codeforces.com/problemset/problem/704/D 题解 对于两种颜色的染色,我们可以把它看做选择问题. 比如说红色的代价小,所以我们尽可能多的染红色. 然后 ...

  4. Visual Studio2015 community 许可证到期问题

    申请微软账户直接登录可以继续使用.

  5. 自定义控件 - 切换开关:SwitchView

    自定义控件一般的几个步骤:1.初始化相关背景图片,布局文件,自定义属性2.设置控件宽高OnMeasure()3.布局或者排版OnLayout()4.绘制控件OnDraw()5.处理触摸事件OnTouc ...

  6. springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

    1.错误 An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, wh ...

  7. uni-app-v-else中不需要值

    这个问题把我都高懵逼了 在vue中, 但是在uni-app中:v-else不需要值, 下面去掉值就Ok了

  8. javascript中json字符串对象转化

    li = [1,2,3,4] s = JSON.stringify(li)  ---转化为字符串 JSON.parse(s) --转化为对象

  9. Java提取文本文档中的所有网址(小案例介绍正则基础知识)

    正则表达式基础以及Java中使用正则查找 定义: 正则表达式是一些用来匹配和处理文本的字符串 正则的基础(先大致了解下) 1. 正则表达式的作用 查找特定的信息(搜索) 替换一些文本(替换) 2. 正 ...

  10. spring data jpa 使用SQL语句查询

    package com.ytkj.entity; import javax.persistence.*; import java.io.Serializable; /** * @Entity * 作用 ...