HDU 4643 GSM (2013多校5 1001题 计算几何)
GSM
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 622 Accepted Submission(s): 206
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.
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
1
2
1
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.
在从u->v的路径上,不断分成两段去做。
很简单
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
using namespace std; const double eps = 1e-;
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
//*两点间距离
inline double dis(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
Point p1[],p2[];
int n,m;
inline int Belong(Point p)
{
int k = ;
double d = dis(p,p2[]);
for(int i = ;i < m;i++)
{
double d2 = dis(p,p2[i]);
if(d2 < d)
{
d = d2;
k = i;
}
}
return k;
}
int solve(Point a,Point b)
{
int k1 = Belong(a);
int k2 = Belong(b);
if(k1 == k2)return ;
if(dis(a,b)<eps)return ;
Point t = Point((a.x+b.x)/,(a.y+b.y)/);
return solve(a,t)+solve(t,b);
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&m) == )
{
for(int i = ;i < n;i++)
p1[i].input();
for(int i = ;i < m;i++)
p2[i].input();
int K;
int u,v;
scanf("%d",&K);
while(K--)
{
scanf("%d%d",&u,&v);
u--;v--;
printf("%d\n",solve(p1[u],p1[v]));
}
}
return ;
}
HDU 4643 GSM (2013多校5 1001题 计算几何)的更多相关文章
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)
Building Fence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- HDU 4643 GSM 暑期多校联合训练第五场 1001
点击打开链接 我就不说官方题解有多坑了 V图那么高端的玩意儿 被精度坑粗翔了 AC前 AC后 简直不敢相信 只能怪自己没注意题目For the distance d1 and d2, if fabs( ...
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- HDU 4611 Balls Rearrangement(2013多校2 1001题)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- hdu 4643 GSM 计算几何 - 点线关系
/* hdu 4643 GSM 计算几何 - 点线关系 N个城市,任意两个城市之间都有沿他们之间直线的铁路 M个基站 问从城市A到城市B需要切换几次基站 当从基站a切换到基站b时,切换的地点就是ab的 ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- skb管理函数之alloc_skb、dev_alloc_skb、kfree_skb、dev_kfree_skb、consume_skb
alloc_skb--分配skb dev_alloc_skb--分配skb,通常被设备驱动用在中断上下文中,它是alloc_skb的封装函数,因为在中断处理函数中被调用,因此要求原子操作(GFP_AT ...
- 源码分析之tinyhttpd-0.1
1. 简介: tinyhttpd是使用c语言开发的超轻量级http服务器,通过代码流程可以了解http服务器的基本处理流程, 并且涉及了网络套接字,线程,父子进程,管道等等知识点: 项目地址:http ...
- python基础===单元测试unittest
''' 编写一个名为Employee 的类,其方法__init__()接受名.姓和年薪,并 将它们都存储在属性中.编写一个名为give_raise()的方法,它默认将年薪增加5000 美元,但也能够接 ...
- [caffe error] undefined reference to `inflateValidate@ZLIB_1.2.9'
undefined reference to `inflateValidate@ZLIB_1.2.9' Makefile.config添加一行LINKFLAGS := -Wl,-rpath,$(HOM ...
- PHP获取ip与ip所在城市
1获取真实ip,本地测试总是::1 或者127.0.0.1 或者局域网的ip /** * 获取用户真实 IP */ function getIP() { static $realip; if (iss ...
- linux命令(14):ifup/ifdown/ip addr命令
开启网卡:ifup eth0 关闭网卡:ifdown eth0 查看网卡接入状态:ip addr[可查看哪块网卡up/down状态]
- linux命令(8):du命令
du –ah:查看文件列表大小 du –sh:查看所有文件的大小总和
- opencv 图像转换
#include <cv.h> #include <highgui.h> int main() { CvPoint2D32f srcTri[], dstTri[]; CvMat ...
- 《java并发编程实战》读书笔记10--显示锁Lock,轮询、定时、读写锁
第13章 显示锁 终于看到了这本书的最后一本分,呼呼呼,真不容易.其实说实在的,我不喜欢半途而废,有其开始,就一定要有结束,否则的话就感觉哪里乖乖的. java5.0之前,在协调对共享对象的访问时可以 ...
- poj 2593&&poj2479(最大两子段和)
Max Sequence Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16850 Accepted: 7054 Des ...