Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6933469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:11+00:00 2026-05-27T11:50:11+00:00

I have set of rectangles ( QGraphicsRectItem in QGraphicsScene ) whose X positions are

  • 0

I have set of rectangles ( QGraphicsRectItem in QGraphicsScene ) whose X positions are fixed and Y positions can be modified. I want to stack these rectangles if there is any overlapping. The positions of rectangles can be changed dynamically by moving/resizing those rectangles and each time it has to optimize the space such that there is no gaps. The important constraint is that , when we move a specific rectangle it has to stack the rectangles without modifying the X position of any other rectangle.

I have a simple brute force algorithm which traverse through all the rectangles and then gets the collidng rectangles , increment the Y position with some delta value for all colliding rectangles.

Any optimal solution for this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:50:12+00:00Added an answer on May 27, 2026 at 11:50 am

    You have to assign each rectangle to a level, so that on a given level, no two rectangles overlap. Correct? So allocate an array of levels, leaving room for the worst-case scenario of each level containing only one rectangle:

    std::vector<int> LevelFreeAt (nRectangles) ;
    

    As you traverse your list of rectangles, LevelFreeAt[i] will contain the time at which level i becomes free. Now for each rectangle, in order of starting time, simply assign it to the first level that is free at its starting time, and update that level’s LevelFreeAt entry accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of rectangles and I would like to reduce the set
I have a grid on which users can draw rectangles (actually rooms in a
I have two rectangles, each identified by a set of four coordinates. I've read
I have set up a simple control with three rectangles, each of which has
i have rectangles and images and i want to show that images on that
My onTouchevent recognizes correct which drawable shape i have clicked. And i can set
I have a set of N positive numbers, and a rectangle of dimensions X
I have a rectangle that I've created and set its individual properties like so
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set a background on the data-role=page element like so <div data-role=page style=background:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.