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. (3.3)狄泰软件学院C++课程学习剖析四

    对课程前面40课的详细回顾分析(二) 1.一个类的成员变量是对于每个对象专有的,但是成员函数是共享的. 2.构造函数只是决定一个对象的初始化状态,而不能决定对象的诞生.二阶构造人为的将初始化过程分为了 ...

  2. 封装类和非封装类比较相同不int和Integer

    A.所有和int(非封装类比较的,只要数值相同就行) B.io3由valueof弄出来的,所以和io1相同 C.io4是new出来的,所以地址不一样,就不相同 D.和A相同

  3. C++返回栈上的数组(局部变量)问题探索

    char* teststr() { char s[] = "hello"; return s; } void main() { char* str = teststr(); ]; ...

  4. 查询数据库对象的DDL信息

    表的DDL select dbms_metadata.get_ddl('HBBL','TABLE','AGREEMENT_MIRROR') from dual:

  5. 前后端分离项目中后台集成shiro需要注意的二三事

    1. 修改 Shiro 认证失败后默认重定向处理问题 a. 继承需要使用的 ShiroFilter,重载 onAccessDenied() 方法: @Override protected boolea ...

  6. Oracle-数据导出和导入

    对数据库进行逻辑备份或数据转储,也就是对数据库实时导入.导出操作时,既可以使用常规的EXP/IMP客户端程序,也可以使用数据泵技术:IMPDP/EXPDP 使用数据泵导出或导入的优点: 1.数据泵导出 ...

  7. Openstack 通过 SQLAlchemy-ORM 访问数据库

    目录 目录 Demo SQLAlchemy 数据库的初始化 数据库的操作实现 数据库的操作请求 全部查询 单个查询 创建 更新 删除 Demo Github/JmilkFan/my-code-repe ...

  8. 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_08 Map集合_3_Map接口中的常用方法

    这个方法比较特殊,它的返回值是V他也就是Vlaue get remove containsKey: put value没有重复的所以v1返回的是null key值有重复,所以会返回被替换的值,范冰冰1 ...

  9. @SuppressWarnings https://www.cnblogs.com/fsjohnhuang/p/4040785.html

    一.前言 编码时我们总会发现如下变量未被使用的警告提示: 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了.这时我们可以在方法前添加 @SuppressWar ...

  10. 查询SQL Server数据库所有表字段备注

    SELECT 表名 = case when a.colorder=1 then d.name else '' end, 表说明 = case when a.colorder=1 then isnull ...