Ultraviolet A 11044-searching for Nessy

Source: Internet
Author: User

Searching for Nessy


The Loch Ness monsteris A mysterous and unidentified 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 investigation 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 concluded that Nessie does not exist.
Now we want to repeat the experiment.

Given a gridNRows and
MColumns representing the loch, 6N,
M10000, find the minimum number
SOf 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,

\ Begin {Center}
\ Mbox {}
\ Epsfbox {p11044.eps}
\ End {center }}$ "align =" Middle "src =" http://uva.onlinejudge.org/external/110/p11044.jpg "width =" 291 "Height =" 362 "> \ begin {Center}
\ Mbox {}
\ Epsfbox {p11044a. EPS}
\ End {center }}$ "align =" Middle "src =" http://uva.onlinejudge.org/external/110/p11044a.gif "width =" 276 "Height =" 325 ">

WhereXRepresents a sonar, And the shaded cells are controlled by their sonar beams; the last figure gives us a solution.

Input

The first 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,
6N,
M10000, that is, the size of the grid (NRows and
MColumns ).

Output

For each test case, the output shoshould consist of one line showing the minimum number of sonars that verifies the conditions above.

Sample Input

 36 67 79 13

Sample output

 4412

Boundary considerations

# Include <stdio. h>
# Include <math. h>
Void main ()
{Int n, m, t, x, y;
Scanf ("% d", & T );
While (t --)
{Scanf ("% d", & N, & M );
N-= 2; m-= 2;
X = N/3; y = m/3;
If (x * 3 <n) ++ X;
If (y * 3 <m) ++ y;
Printf ("% d \ n", x * y );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.