Example #1
0
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   int[] a = new int[n];
   for (int i = 0; i < n; i++) {
     a[i] = in.nextInt();
   }
   int res = new A1().maxArea(a);
   out.println(res);
 }
Example #2
0
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   ArrayList<String> a = new ArrayList<>();
   for (int i = 0; i < n; i++) {
     a.add(in.next());
   }
   TreeNode tree = new TreeNode(a);
   int res = new A1().maxPathSum(tree);
   out.println(res);
 }
Example #3
0
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   int[] a = new int[n];
   for (int i = 0; i < n; i++) {
     a[i] = in.nextInt();
   }
   new A1().nextPermutation(a);
   for (int i = 0; i < a.length; i++) {
     out.println(a[i]);
   }
 }
Example #4
0
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   int x = in.nextInt();
   ListNode head = new ListNode(-1);
   ListNode p = head;
   for (int i = 0; i < n; i++) {
     p.next = new ListNode(in.nextInt());
     p = p.next;
     //            out.println(p.val);
   }
   ListNode res = new A1().partition(head.next, x);
   p = res;
   while (p != null) {
     out.println(p.val);
     p = p.next;
   }
 }
Example #5
0
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   int[][] g = new int[n][n];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       g[i][j] = in.nextInt();
     }
   }
   Queue<int[]> queue =
       new PriorityQueue<int[]>(
           1,
           new Comparator<int[]>() {
             @Override
             public int compare(int[] o1, int[] o2) {
               return o1[1] - o2[1];
             }
           });
   queue.add(new int[] {0, 0});
   boolean[] visited = new boolean[n];
   int res = 0;
   while (!queue.isEmpty()) {
     int[] head = queue.remove();
     int node = head[0];
     int dist = head[1];
     if (!visited[node]) {
       res += dist;
       visited[node] = true;
       for (int i = 0; i < n; i++) {
         if (!visited[i]) {
           queue.add(new int[] {i, g[node][i]});
         }
       }
     }
   }
   out.println(res);
 }
Example #6
0
 public void solve(InputReader in, OutputWriter out) {
   int x = in.nextInt();
   boolean res = new A1().isPalindrome(x);
   out.println(res);
 }