mardi 1 janvier 2019

Identifying a square in a square

Good evening.

I am learning c++ and im currently at a halt in this project.

I am trying to make a function that would be able to spot a certain sub-square in a square.

It starts as: 1) Input a one dimensional vector with nxn number of elements representing an nxn square and a number representing the subqaure needed 2) A subquare in this is equal to the size of sqrtn x sqrtn such that there are n number of sub-squares in one square. e.g a 9by9 square has 9 smaller squares in it and a 16by16 has 4 smaller squares in it. 3)Save the elements in the sub square given in an output vector using push_back.

My only issue is that I am finding it hard to be able to locate sub-squares. I looked at turning the one dimensional input vector into a 2D array and then creating some sort of algorithm based on row column and sub square number to try to pull out the index of these elements and put them into the output vector but this does not seem to be efficient nor did it seem possible.

For example if you had a 4 by 4 square the index of the 4 sub square would be

0,0 0,1 1,0 1,1

then 0,2 0,3 1,2 1,3

then 2,0 2,1 3,0 3,1

then 2,2 2,3 3,2 3,3

Does not seem to have an arithmetic or geometric sequence unless I am mistaken.

So I started thinking about trying to identify them using the border of the square but this may be far fetched.

Does anyone have have any ideas what would be a good way to go about this?

Many thanks.

Aucun commentaire:

Enregistrer un commentaire