Note that there are some explanatory texts on larger screens.

plurals
  1. PODetecting shapes in a "bitmap"
    primarykey
    data
    text
    <p>So,preparing myself for the next ieextreme competition I was going through some past problems.I found one that really troubles me,since I can't figure out what to do.I could probably make it using some bruteforce 300 lines code,but I think that this is not what someone is supposed to do in such competitions,so I need your help!!</p> <p><strong>Detecting shapes in a bitmap</strong></p> <p>Problem statement: In image analysis, it is common to analyze a bitmap and observe the shapes present in it. For this problem, design an algorithm to detect shapes in a given bitmap. The shapes present in the map shall be from the set Square, Rectangle, Triangle and Parallelogram.</p> <p>In the bitmap each pixel is represented as a bit, 1 - representing black and 0 - representing white. Participants are expected to detect the shapes outlined in black. Input The first line will contain the size of the bit map in pixels represented as (Row,Column).</p> <p>E.g. 6,8 this means a bit map of 6 rows and 8 columns. The next line will contain a series of decimal digits from 0 to 255 separated by spaces. Each digit will represent a collection of 8 binary bits in the bitmap. IE. 55 represents a binary pattern 00110111.</p> <p>Note: There can be multiple shapes in a bitmap and NO shapes shall intersect. However there can be shapes nested with each other without any intersection. </p> <p>Output The shapes present in the bitmap in ascending order of their names, separated by a comma and a space. Eg. Rectangle, Square, Triangle</p> <p>Note: There is NO linefeed or space at the end of the output If any shape repeats, the output should contain as many repetitions as in the bitmap. ie. If there are 2 squares and one triangle, the output shall be Square, Square, Triangle </p> <p>Example Set 1 </p> <p>Input: </p> <p>6 8</p> <p>0 126 66 66 126 0</p> <p>Output: Rectangle </p> <p>Example Set 2</p> <p>Input: </p> <p>6 16 </p> <p>0 0 120 120 72 144 73 32 123 192 0 0 </p> <p>Output: Parallelogram, Square</p> <p>I have written this code so that I can visualize the bitmap and have 2 lists(bitmap in rows and cols)...</p> <pre><code>rows,cols=(int(i) for i in raw_input().split()) nums=[int(n) for n in raw_input().split()] mr=[] for i in range(0,len(nums),cols/8): row='' for j in range(i,i+cols/8): b=bin(nums[j])[2:] b='0'*(8-len(b))+b row+=b mr.append(row) mc=[''.join([mr[i][j] for i in range(rows)]) for j in range(cols)] </code></pre> <p>Thank you for your time...Please answer if you can in Python,C++ or Ruby,since these are the languages I can understand or even algorithmically...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload