Connection Status:
Competition Arena > TheRoundCityDiv2
SRM 734 · 2018-05-16 · by Vasyl[alphacom] · Brute Force, Simple Math
Class Name: TheRoundCityDiv2
Return Type: int
Method Name: find
Arg Types: (int)
Problem Statement

Problem Statement

John and Brus have found a nice horizontal plane and they built a round city somewhere on the plane. The center of the city is at coordinates (0, 0). This point is left empty. There is a house at each other lattice point that is at most r units away from the city center. That is, the lattice point (x, y) other than (0, 0) contains a house if and only if sqrt(x*x + y*y) ≤ r.

John and Brus now want to count all houses in the city. You are given the int r. Return the number of houses.

Constraints

  • r will be between 1 and 100, inclusive.
Examples
0)
1
Returns: 4

There are four houses in the city: (0, 1), (0, -1), (1, 0) and (-1, 0).

1)
2
Returns: 12

There are twelve houses in the city: (0, 1), (0, -1), (1, 0), (-1, 0), (0, 2), (0, -2), (2, 0), (-2, 0), (1, 1), (1, -1), (-1, 1) and (-1, -1).

2)
3
Returns: 28

There are twenty-eight houses in the city: (0, 1), (0, -1), (1, 0), (-1, 0), (0, 2), (0, -2), (2, 0), (-2, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), (0, 3), (0, -3), (3, 0), (-3, 0), (1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1), (2, 2), (2, -2), (-2, 2) and (-2, -2).

3)
47
Returns: 6920
4)
96
Returns: 28916

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

Coding Area

Language: C++17 · define a public class TheRoundCityDiv2 with a public method int find(int r) · 47 test cases · 2 s / 256 MB per case

Submitting as anonymous