Searching for Nessy
2015-08-02 16:56
239 查看
Searching for Nessy
he Loch Ness Monsteris a mysterious and unidenti ed animal said to inhabit Loch Ness, a large deep
freshwater loch near the city of Inverness in northern Scotland. Nessie is usually categorized as a type
of lake monster.
http://en.wikipedia.org/wiki/Loch
Ness
Monster
In July 2003, the BBC reported an extensive investiga-
tion of Loch Ness by a BBC team, using 600 separate sonar
beams, found no trace of any \sea monster" (i.e., any large
animal, known or unknown) in the loch. The BBC team con-
cluded that Nessie does not exist. Now we want to repeat the
experiment.
Given a grid of
n
rows and
m
columns representing the
loch, 6
n
,
m
10000, nd the minimum number
s
of sonar
beams you must put in the square such that we can control
every position in the grid, with the following conditions:
•
one sonar occupies one position in the grid; the sonar
beam controls its own cell and the contiguous cells;
•
the border cells do not need to be controlled, because
Nessy cannot hide there (she is too big).
For example,
where
X
represents a sonar, and the shaded cells are controlled by their sonar beams; the last gure
gives us a solution.
Input
The rst line of the input contains an integer,
t
, indicating the number of test cases. For each test case,
there is a line with two numbers separated by blanks, 6
n
,
m
10000, that is, the size of the grid (
n
rows and
m
columns).
Output
For each test case, the output should consist of one line showing the minimum number of sonars that
veri es the conditions above.
SampleInput
3
6 6
7 7
9 13
SampleOutput
4
4
12
大意:
一个声呐可以探测一个3*3的方格,给出m*n的方格,求出最少用多少个声呐可以全部探测完;
边缘地带不用探测;
代码:
#include <stdio.h>
int main(){
int num;
scanf ("%d", &num);
getchar();
while (num--){
int m, n;
scanf ("%d %d", &m, &n);
getchar();
m = m / 3;
n = n / 3;
printf("%d\n", m * n);
}
return 0;
}
he Loch Ness Monsteris a mysterious and unidenti ed animal said to inhabit Loch Ness, a large deep
freshwater loch near the city of Inverness in northern Scotland. Nessie is usually categorized as a type
of lake monster.
http://en.wikipedia.org/wiki/Loch
Ness
Monster
In July 2003, the BBC reported an extensive investiga-
tion of Loch Ness by a BBC team, using 600 separate sonar
beams, found no trace of any \sea monster" (i.e., any large
animal, known or unknown) in the loch. The BBC team con-
cluded that Nessie does not exist. Now we want to repeat the
experiment.
Given a grid of
n
rows and
m
columns representing the
loch, 6
n
,
m
10000, nd the minimum number
s
of sonar
beams you must put in the square such that we can control
every position in the grid, with the following conditions:
•
one sonar occupies one position in the grid; the sonar
beam controls its own cell and the contiguous cells;
•
the border cells do not need to be controlled, because
Nessy cannot hide there (she is too big).
For example,
where
X
represents a sonar, and the shaded cells are controlled by their sonar beams; the last gure
gives us a solution.
Input
The rst line of the input contains an integer,
t
, indicating the number of test cases. For each test case,
there is a line with two numbers separated by blanks, 6
n
,
m
10000, that is, the size of the grid (
n
rows and
m
columns).
Output
For each test case, the output should consist of one line showing the minimum number of sonars that
veri es the conditions above.
SampleInput
3
6 6
7 7
9 13
SampleOutput
4
4
12
大意:
一个声呐可以探测一个3*3的方格,给出m*n的方格,求出最少用多少个声呐可以全部探测完;
边缘地带不用探测;
代码:
#include <stdio.h>
int main(){
int num;
scanf ("%d", &num);
getchar();
while (num--){
int m, n;
scanf ("%d %d", &m, &n);
getchar();
m = m / 3;
n = n / 3;
printf("%d\n", m * n);
}
return 0;
}
相关文章推荐
- HibernateTemplate实现分页
- JSON4:嵌套的JsonObject与JSONArray的取值
- 华为是怎样研发的(3)——专题分析
- 华为是怎样研发的(4)——器件选型
- Photoshop 画笔工具下的模式选择的使用
- Tarena - 转义字符与类型转换
- @MappedSuperclass 介绍
- HDOJ 5298 Solid Geometry Homework
- 北大ACM3233——Matrix Power Series
- System类的学习
- IOS StoryBoard简单说明
- osgi 运行错误
- Kotlin语言文档翻译项目
- Fragment的练习
- [leetcode] 216.Combination Sum III
- 并查集
- HDU 1870.愚人节的礼物【字符串处理】【思维练习】【8月2】
- Ip 子网掩码 物理地址 验证
- shell编程
- 我对建立时间和保持时间的理解