Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 173 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class PageLayout {
  4.     private static int nDescriptions;
  5.     private static ArrayList<Story> stories;
  6.  
  7.     public static void main(String[] args) {
  8.         Kattio sc = new Kattio(System.in);
  9.         nDescriptions = sc.getInt();
  10.         while(nDescriptions > 0) {
  11.             stories = new ArrayList<>(nDescriptions);
  12.             for (int i = 0; i < nDescriptions; i++) {
  13.                 stories.add(new Story(sc.getInt(), sc.getInt(),sc.getInt(), sc.getInt()));
  14.             }
  15.             sc.println(maxArea(0, 0));
  16.             nDescriptions = sc.getInt();
  17.         }
  18.         sc.flush();
  19.     }
  20.  
  21.     private static int maxArea(int i, int current) {
  22.         if (i == nDescriptions) return 0;
  23.         int withOut = maxArea(i+1, current);
  24.  
  25.         Story iStory = stories.get(i);
  26.         for (int j = 0; j < i; j++) {
  27.             if ((current >>j) % 2 == 1) {
  28.                 Story jStory = stories.get(j);
  29.                 if (iStory.overlaps(jStory)) {
  30.                     return withOut;
  31.                 }
  32.             }
  33.         }
  34.         return Math.max(iStory.width*iStory.height + maxArea(i+1, current|(1<<i)), withOut);
  35.     }
  36. }
  37. class Story {
  38.     int width;
  39.     int height;
  40.     int x;
  41.     int y;
  42.  
  43.     Story(int width, int height, int x, int y) {
  44.         this.width = width;
  45.         this.height = height;
  46.         this.x = x;
  47.         this.y = y;
  48.     }
  49.  
  50.     public boolean overlaps(Story jStory) {
  51.         return this.x+width > jStory.x && jStory.x+jStory.width > this.x &&
  52.                 this.y+height > jStory.y && jStory.y+jStory.height > this.y;
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top