Connection Status:
Competition Arena > DrawCircle
SRM 140 · 2003-03-26 · by Yarin
Class Name: DrawCircle
Return Type: String[]
Method Name: circle
Arg Types: (int)
Problem Statement

Problem Statement

As part of a drawing program, you need a routine which draws a circle of a given radius onto a bitmap. A pixel in the bitmap is considered to lie on the edge of the (infinitely thin) circle if some part of the pixel lies within the circle and some part of the pixel lies outside it; see the picture below.



The circle above has radius 8. Each square in the picture corresponds to a pixel in the bitmap. The center of the circle is in the middle of the center square of the bitmap. The white squares are the pixels entirely outside the circle, the light gray squares are the pixels entirely within the circle, and the dark squares are the pixels which partly lies both inside and outside of the circle.

Create a class DrawCircle containing the method circle which takes as input an int radius containing the radius of the circle, and which returns a String[] containing the bitmap with the drawn circle in the center. Each character in the return value correspond to a pixel; '.' for pixels outside the circle, 'x' for pixels inside the circle and '#' for pixels on the edge of the circle. The return value should contain radius*2+1 elements, each element containing radius*2+1 characters.

Notes

  • The circle never touches the corners of the pixels for any of the possible input values.
  • If you are using a plugin so you don't see the picture, you may want to read the problem statement in the applet.

Constraints

  • radius will be between 1 and 24, inclusive.
Examples
0)
8
Returns: { ".....#######.....",  "...###xxxxx###...",  "..##xxxxxxxxx##..",  ".##xxxxxxxxxxx##.",  ".#xxxxxxxxxxxxx#.",  "##xxxxxxxxxxxxx##",  "#xxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxx#",  "##xxxxxxxxxxxxx##",  ".#xxxxxxxxxxxxx#.",  ".##xxxxxxxxxxx##.",  "..##xxxxxxxxx##..",  "...###xxxxx###...",  ".....#######....." }

This is the same case as the picture above.

1)
1
Returns: { "###",  "#x#",  "###" }
2)
15
Returns: { "...........#########...........",  "........####xxxxxxx####........",  ".......##xxxxxxxxxxxxx##.......",  ".....###xxxxxxxxxxxxxxx###.....",  "....##xxxxxxxxxxxxxxxxxxx##....",  "...##xxxxxxxxxxxxxxxxxxxxx##...",  "...#xxxxxxxxxxxxxxxxxxxxxxx#...",  "..##xxxxxxxxxxxxxxxxxxxxxxx##..",  ".##xxxxxxxxxxxxxxxxxxxxxxxxx##.",  ".#xxxxxxxxxxxxxxxxxxxxxxxxxxx#.",  ".#xxxxxxxxxxxxxxxxxxxxxxxxxxx#.",  "##xxxxxxxxxxxxxxxxxxxxxxxxxxx##",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "#xxxxxxxxxxxxxxxxxxxxxxxxxxxxx#",  "##xxxxxxxxxxxxxxxxxxxxxxxxxxx##",  ".#xxxxxxxxxxxxxxxxxxxxxxxxxxx#.",  ".#xxxxxxxxxxxxxxxxxxxxxxxxxxx#.",  ".##xxxxxxxxxxxxxxxxxxxxxxxxx##.",  "..##xxxxxxxxxxxxxxxxxxxxxxx##..",  "...#xxxxxxxxxxxxxxxxxxxxxxx#...",  "...##xxxxxxxxxxxxxxxxxxxxx##...",  "....##xxxxxxxxxxxxxxxxxxx##....",  ".....###xxxxxxxxxxxxxxx###.....",  ".......##xxxxxxxxxxxxx##.......",  "........####xxxxxxx####........",  "...........#########..........." }
3)
2
Returns: { ".###.",  "##x##",  "#xxx#",  "##x##",  ".###." }
4)
3
Returns: { ".#####.",  "##xxx##",  "#xxxxx#",  "#xxxxx#",  "#xxxxx#",  "##xxx##",  ".#####." }

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

Coding Area

Language: C++17 · define a public class DrawCircle with a public method vector<string> circle(int radius) · 31 test cases · 2 s / 256 MB per case

Submitting as anonymous