DrawCircle
SRM 140 · 2003-03-26 · by Yarin
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
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.
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
Returns: { "###", "#x#", "###" }
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####........", "...........#########..........." }
2
Returns: { ".###.", "##x##", "#xxx#", "##x##", ".###." }
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.
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