Ejemplo n.º 1
0
    //
    // Runnable interface
    //
    public void run() {

      // output all active probes
      for (PerformanceProbe probe : list(ALL_RECORDERS)) {
        probe.output("F");
      }

      // close output if not standard output
      if (!outputStream.equals(System.out)) {
        outputStream.close();
      }
    }
Ejemplo n.º 2
0
 /** @param args */
 public static void main(String[] args) {
   JumpFurther t = new JumpFurther();
   int n = 1313;
   int bad = 5858;
   int r = t.furthest(n, bad);
   out.println(r);
 }
Ejemplo n.º 3
0
 /** @param args */
 public static void main(String[] args) {
   MaxMinTreeGame t = new MaxMinTreeGame();
   int[] a = {0, 0};
   int[] b = {3, 2, 5};
   int r = t.findend(a, b);
   out.println(r);
 }
Ejemplo n.º 4
0
 /** @param args */
 public static void main(String[] args) {
   LittleElephantAndString t = new LittleElephantAndString();
   String a = "DCABA";
   String B = "DACBA";
   int r = t.getNumber(a, B);
   out.println(r);
 }
Ejemplo n.º 5
0
 //
 // PROBE OUTPUT
 //
 private void output(String type) {
   StringBuffer result = new StringBuffer(128);
   result.append(time()).append(" ");
   result.append(type).append(" ");
   result.append(probeName).append(": ");
   result.append(toString());
   outputStream.println(result.toString());
 }
Ejemplo n.º 6
0
  /**
   * Changes the output of all probes to the specified file. This method may be called multiple
   * times during the execution of the JVM.
   *
   * @param pathname the pathname of the output file.
   */
  public static void setOutput(String pathname) {

    // open specified file
    PrintStream previous = outputStream;
    try {
      outputStream = new PrintStream(new FileOutputStream(pathname));
    } catch (FileNotFoundException e) {
      // if file cannot be opened, output remains unchanged
      return;
    }

    // close previous output if not standard output
    if (previous != null && !previous.equals(System.out)) {
      previous.close();
    }

    // print date and time
    Format format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    outputStream.println("Starting on " + format.format(new Date()));
  }
Ejemplo n.º 7
0
  public void solve() throws Exception {
    P[] ps = new P[N];
    Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
    for (int i = 0; i < N; i++) {
      P p = new P();
      p.x = sc.nextInt();
      p.y = sc.nextInt();
      ps[i] = p;
      if (!map.containsKey(p.x)) {
        Set<Integer> set = new HashSet<Integer>();
        map.put(p.x, set);
      }
      map.get(p.x).add(p.y);
    }
    Arrays.sort(
        ps,
        new Comparator<P>() {
          @Override
          public int compare(P p1, P p2) {
            if (p1.x != p2.x) {
              return p1.x - p2.x;
            }
            return p1.y - p2.y;
          }
        });

    List<Pair> yp = new ArrayList<Pair>();
    for (int i = 0; i < ps.length - 1; i++) {
      if (ps[i].x != ps[i + 1].x) continue;
      int lidx = i + 1;
      while (lidx + 1 < ps.length && ps[i].x == ps[lidx + 1].x) {
        lidx++;
      }
      Pair pair = new Pair();
      pair.s = ps[i].y;
      pair.l = ps[lidx].y;
      pair.base = ps[i].x;
      yp.add(pair);
      i = lidx;
    }

    Arrays.sort(
        ps,
        new Comparator<P>() {
          @Override
          public int compare(P p1, P p2) {
            if (p1.y != p2.y) {
              return p1.y - p2.y;
            }
            return p1.x - p2.x;
          }
        });
    List<Pair> xp = new ArrayList<Pair>();
    for (int i = 0; i < ps.length - 1; i++) {
      if (ps[i].y != ps[i + 1].y) continue;
      int lidx = i + 1;
      while (lidx + 1 < ps.length && ps[i].y == ps[lidx + 1].y) {
        lidx++;
      }
      Pair pair = new Pair();
      pair.s = ps[i].x;
      pair.l = ps[lidx].x;
      pair.base = ps[i].y;
      xp.add(pair);
      i = lidx;
    }

    int ans = 0;
    for (int i = 0; i < yp.size(); i++) {
      int xnow = yp.get(i).base;
      int sy = yp.get(i).s;
      int ly = yp.get(i).l;
      for (int j = 0; j < xp.size(); j++) {
        int y = xp.get(j).base;
        if (y < sy || ly < y) continue;
        if (xp.get(j).s > xnow || xp.get(j).l < xnow) continue;
        try {
          if (!map.get(xnow).contains(y)) {
            ans++;
            map.get(xnow).add(y);
          }
        } catch (Exception ex) {

        }
      }
    }
    ans += ps.length;
    out.println(ans);
  }
Ejemplo n.º 8
0
 /** @param args */
 public static void main(String[] args) {
   CarrotJumping t = new CarrotJumping();
   int r = t.theJump(852808441);
   out.println(r);
 }