Connection Status:
Competition Arena > TheNewHouseDivTwo
SRM 445 · 2009-07-23 · by Vasyl[alphacom] · Geometry, Simple Search, Iteration
Class Name: TheNewHouseDivTwo
Return Type: int
Method Name: count
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

John is obsessed with security. He has several old houses and he wants to build a new one. John is very afraid of thieves, so he will choose the location of the new house using the following rule. There should be at least one old house directly to the North of the new one (i.e., with the same x coordinate and a greater y coordinate), at least one directly to the South, at least one directly to the West and at least one directly to the East.

You are given the locations of John's old houses in int[]s x and y. The i-th old house is located at (x[i], y[i]). Return the number of possible locations for the new house.

Notes

  • Several houses can be located at the same point.

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • x and y will contain the same number of elements.
  • Each element of x will be between -100 and 100, inclusive.
  • Each element of y will be between -100 and 100, inclusive.
Examples
0)
{-1, 1, 0, 0}
{0, 0, -1, 1}
Returns: 1

The origin (0, 0) is the only possible location for the new house.

1)
{4, 5, 0, 8, -3, 5, 4, 7}
{9, -4, 2, 1, 1, 11, 0, 2}
Returns: 4

Here the possible locations are (4, 1), (4, 2), (5, 1) and (5, 2).

2)
{4, 4, 4}
{7, 7, 7}
Returns: 0

All the houses are at the same point.

3)
{1, 7, 3, 4, 9, 3, 7, 1, 1, 6, 1, 6, 1, 9, 7, 9, 4, 9, 1, 4, 7, 1, 2, 5, 3, 8, 7, 7, 1}
{7, 2, 8, 9, 4, 3, 4, 1, 4, 1, 7, 8, 1, 1, 1, 4, 7, 1, 9, 4, 9, 1, 4, 1, 1, 1, 2, 4, 3}
Returns: 5
4)
{44, -73, -78, 59, -55, 35, -25, 55, -80, -61, 31, 47, -94, 57, -13, 92, -72, -29, 17, 23, 98, -82, -48, -6, -91, -43, 99, -88, 20, -24, 53, -14, -56, 5, -88, -16, -28}
{64, 17, -76, 95, 53, 62, 6, 42, 98, 53, -14, 91, 44, 81, 23, -42, -42, 2, 80, -91, 28, -13, -15, 93, -65, 79, -1, -35, 7, -75, -54, 74, 53, -62, 53, 23, -98}
Returns: 0

Submissions are judged against all 67 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheNewHouseDivTwo with a public method int count(vector<int> x, vector<int> y) · 67 test cases · 2 s / 256 MB per case

Submitting as anonymous