Douma37

balls container

Aug 13th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1.     static String organizingContainers(int[][] container) {
  2.         boolean res = false;
  3.         int n = container.length;
  4.         for (int i = 0; i < n; i++) {
  5.             // number of balls of different colour than i
  6.             for (int j = 0; j < n; j++) {
  7.                 int diffBalls = 0;
  8.                 for (int k = 0; k < n; k++) {
  9.                     if (k != i) {
  10.                         diffBalls += container[j][k];
  11.                     }
  12.                 }
  13.                 // number of balls of colour i in different containers
  14.                 int ballsOutside = 0;
  15.                 for (int k = 0; k < n; k++) {
  16.                     if (k != j) {
  17.                         ballsOutside += container[k][i];
  18.                     }
  19.                 }
  20.                 res |= ballsOutside == diffBalls;
  21.             }
  22.             System.out.println(res);
  23.            
  24.         }
  25.         return res ? "Possible" : "Impossible";
  26.  
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment