Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.58 KB | None | 0 0
  1. z1  = zeros(1000); % overlap count
  2. z   = zeros(1000); % latest index
  3. t   = textscan(fopen('input.txt'),'#%f%*s%f,%f:%fx%f');
  4. id  = t{1};
  5. L   = t{2}+1;
  6. T   = t{3}+1;
  7. w   = t{4};
  8. h   = t{5};
  9.  
  10. for i=1:length(t{1})
  11.     z1(T(i):T(i)+h(i)-1,L(i):L(i)+w(i)-1)   = z1(T(i):T(i)+h(i)-1,L(i):L(i)+w(i)-1)+1;
  12.     z(T(i):T(i)+h(i)-1,L(i):L(i)+w(i)-1)    = id(i);
  13. end
  14. disp(sum(sum(z1>1))) % Part 1
  15.  
  16. z = z.*(z1==1); %only consider spaces that have not been overlapped
  17. for i=1:length(t{1})
  18.     if sum(sum(z==id(i))) == w(i)*h(i)
  19.         disp(id(i)) % Part 2
  20.         break
  21.     end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement