您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: