更新时间:2022-08-15 14:36:50
我们的乐乐同学对于网络可算得上是情有独钟,他有一个计划,那就是用无线网覆盖郑州大学。
现在学校给了他一个机会,因此他要购买很多的无线路由。现在他正在部署某条大道的网络,而学校只允许把他的无线路由器放在路的正中间。我们默认这条大道是笔直的并且它在任何地方的宽度都一样。并且所有的路由器的覆盖面积是相同的。现在乐乐计算出这条大道的长和宽,以及路由器的覆盖半径,想请你帮忙,帮他计算出他最少要购买的路由器的数量。
注意:为了防止某种干扰,两台无线路由之间的最小距离不能小于1米
图1中为一条矩形的道路,中间的虚线代表中线。图2为最小覆盖的示意图。
2 40 6 5 40 10 5
5 impossible
01.
#include <iostream>
02.
#include <cmath>
03.
using
namespace
std;
04.
05.
int
main()
06.
{
07.
int
testNum;
08.
09.
cin >> testNum;
10.
while
(testNum--)
11.
{
12.
int
nLength,
//长
13.
nWidth,
//宽
14.
nRadix;
//覆盖半径
15.
16.
cin >> nLength >> nWidth >> nRadix;
17.
18.
if
(2 * nRadix < nWidth)
19.
{
20.
cout <<
"impossible\n"
;
21.
continue
;
22.
}
23.
double
distance = nRadix * nRadix - (nWidth / 2.0) * (nWidth / 2.0);
24.
if
(distance <= 0)
25.
{
26.
cout <<
"impossible\n"
;
27.
continue
;
28.
}
29.
distance =
sqrt
(distance);
30.
//用ceil函数返回不小它的最小整数
31.
cout <<
ceil
((nLength / (distance * 2))) << endl;
32.
}
33.
return
0;
34.
}