Advertisement
matbiz01

Rectangle fit

Jun 15th, 2023
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. class Size {
  6. public:
  7.     int x;
  8.     int y;
  9.     Size(int x, int y): x(x), y(y){}
  10.     int getArea(){
  11.         return x * y;
  12.     }
  13. };
  14.  
  15. void print(std::vector<Size> sizes){
  16.     std::cout << "printing" << std::endl;
  17.     for(auto size: sizes){
  18.         std::cout << "x: " << size.x << ", y: " << size.y << std::endl;
  19.     }
  20. }
  21.  
  22. void printOccupied(std::vector<std::vector<bool>> occupied){
  23.     for(auto line: occupied){
  24.         std::string row;
  25.         for(auto val: line){
  26.             row += std::to_string(val) + " ";
  27.         }
  28.         std::cout << row << std::endl;
  29.     }
  30. }
  31.  
  32. void fits(int x, int y, Size size, std::vector<std::vector<bool>> occupied){
  33.     for(int i = x; i < x + size.x; i++){
  34.         for(int j = y; j < y + size.y; j++){
  35.             if(occupied.at(j).at(i)) return false;
  36.         }
  37.     }
  38.     return true;
  39. }
  40.  
  41. int main()
  42. {
  43.     std::vector<Size> sizes;
  44.     for(int i = 2; i < 7; i += 4){
  45.         for(int j = 1; j < 8; j += 4){
  46.             sizes.push_back(Size(i, j));
  47.         }
  48.     }
  49.    
  50.     for(int i = 0; i < 15; i++){
  51.         sizes.push_back(Size(1, 1));
  52.     }
  53.    
  54.     sizes.insert(sizes.begin(), Size(20, 20));
  55.    
  56.     std::sort(sizes.begin(), sizes.end(),
  57.         [](const Size &a, const Size &b){
  58.             return a.x * a.y > b.x * b.y;
  59.         }
  60.     );
  61.    
  62.    
  63.     std::vector<std::vector<bool>> occupied(sizes[0].y, std::vector<bool>(sizes[0].x));
  64.     std::cout << occupied[0][0] << std::endl;
  65.    
  66.     for(auto size: sizes){
  67.         for(int i = 0; i < size.y; i++){
  68.             for(int j = 0; j < size.x; j++){
  69.                
  70.             }
  71.         }
  72.     }
  73.    
  74.    
  75.     printOccupied(occupied);
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement