Example #1
1
 public BigInteger count(int n) {
   BigInteger[] prev = new BigInteger[k];
   Arrays.fill(prev, BigInteger.ZERO);
   prev[s] = BigInteger.ONE;
   while (n-- > 0) {
     BigInteger[] next = new BigInteger[k];
     Arrays.fill(next, BigInteger.ZERO);
     for (int i = 0; i < k; ++i) {
       if (prev[i].signum() <= 0) {
         continue;
       }
       for (int j = 0; j < z; ++j) {
         if (e[j][i] < 0) {
           continue;
         }
         next[e[j][i]] = next[e[j][i]].add(prev[i]);
       }
     }
     prev = next;
   }
   BigInteger ans = BigInteger.ZERO;
   for (int term : t) {
     ans = ans.add(prev[term]);
   }
   return ans;
 }
  int Query() {
    int minimum = 100001;

    visited = new boolean[V];
    Arrays.fill(visited, false);

    depth = new int[V];
    Arrays.fill(depth, -1);

    low = new int[V];
    Arrays.fill(low, -1);

    parent = new int[V];
    Arrays.fill(parent, -1);

    articulationPoints = new TreeMap<Integer, Boolean>();

    getArticulationPoints(0, 0);

    for (Map.Entry<Integer, Boolean> entry : articulationPoints.entrySet()) {
      int i = (int) entry.getKey();
      if (RatingScore[i] < minimum) {
        minimum = RatingScore[i];
      }
    }

    return minimum != 100001 ? minimum : -1;
  }
Example #3
0
 // [algo] hungary BipartiteMaximumMatching
 // [module] hungary
 public static int hungary(int nu, int nv, int[][] e, int[] mu, int[] mv) {
   Arrays.fill(mu, -1);
   Arrays.fill(mv, -1);
   int[] q = new int[nu];
   int[] p = new int[nv];
   int ret = 0;
   for (int i = 0; i < nu; ++i) {
     Arrays.fill(p, -1);
     q[0] = i;
     BFS:
     for (int begin = 0, end = 1; begin < end; ++begin) {
       int u = q[begin];
       for (int v : e[u]) {
         if (p[v] == -1) {
           p[v] = u;
           if (mv[v] == -1) {
             int t = v;
             while (t != -1) {
               u = p[t];
               v = t;
               t = mu[u];
               mu[u] = v;
               mv[v] = u;
             }
             ++ret;
             break BFS;
           } else {
             q[end++] = mv[v];
           }
         }
       }
     }
   }
   return ret;
 }
  static double[] similarity(LatentDirichletAllocation lda0, LatentDirichletAllocation lda1) {

    int numTopics = lda0.numTopics();

    int numPairs = numTopics * (numTopics - 1);
    @SuppressWarnings({"unchecked", "rawtypes"}) // ok given use w. erasure
    ScoredObject<int[]>[] pairs = (ScoredObject<int[]>[]) new ScoredObject[numPairs];
    int pos = 0;
    for (int i = 0; i < numTopics; ++i) {
      for (int j = 0; j < numTopics; ++j) {
        if (i == j) continue;
        double divergence =
            Statistics.symmetrizedKlDivergence(
                lda0.wordProbabilities(i), lda1.wordProbabilities(j));
        pairs[pos++] = new ScoredObject<int[]>(new int[] {i, j}, divergence);
      }
    }
    Arrays.sort(pairs, ScoredObject.comparator());
    boolean[] taken0 = new boolean[numTopics];
    Arrays.fill(taken0, false);
    boolean[] taken1 = new boolean[numTopics];
    Arrays.fill(taken1, false);
    double[] scores = new double[numTopics];
    int scorePos = 0;
    for (pos = 0; pos < numPairs && scorePos < numTopics; ++pos) {
      int[] pair = pairs[pos].getObject();
      if (!taken0[pair[0]] && !taken1[pair[1]]) {
        taken0[pair[0]] = true;
        taken1[pair[1]] = true;
        scores[scorePos++] = pairs[pos].score();
      }
    }
    return scores;
  }
Example #5
0
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    int cases = 1;
    while (true) {
      st = new StringTokenizer(in.readLine());
      n = Integer.parseInt(st.nextToken());
      m = Integer.parseInt(st.nextToken());
      if (n == 0 && m == 0) break;
      a = new int[n];
      b = new int[m];
      dp = new int[n + 1][m + 1];
      st = new StringTokenizer(in.readLine());
      for (int i = 0; i < n; i++) {
        a[i] = Integer.parseInt(st.nextToken());
        Arrays.fill(dp[i], -1);
      }
      Arrays.fill(dp[n], -1);
      st = new StringTokenizer(in.readLine());
      for (int i = 0; i < m; i++) b[i] = Integer.parseInt(st.nextToken());

      System.out.println("Twin Towers #" + cases);
      System.out.println("Number of Tiles : " + LCS(0, 0));
      System.out.println();
      cases++;
    }
    in.close();
    System.exit(0);
  }
Example #6
0
  public int minimalPlanets(int[] A, int[] B) {
    this.A = A.length > B.length ? A : B;
    this.B = A.length > B.length ? B : A;

    int[][] memo = new int[this.A.length][this.B.length];
    for (int[] m : memo) {
      Arrays.fill(m, -1);
    }

    int best = find(memo, 0, 0, 1, 1);
    for (int i = 0; i < this.A.length; i++) {
      for (int j = 0; j < this.B.length; j++) {
        if (this.A[i] != this.B[j]) {

          memo = new int[this.A.length][this.B.length];
          for (int[] m : memo) {
            Arrays.fill(m, -1);
          }

          best = Math.max(best, find(memo, 0, 0, this.B[j], this.A[i]));
        }
      }
    }

    return A.length + (B.length - best);
  }
 public void clear() {
   super.clear();
   final int[] keys = this._set;
   final Object[] vals = this._values;
   final byte[] states = this._states;
   Arrays.fill(this._set, 0, this._set.length, 0);
   Arrays.fill(this._values, 0, this._values.length, null);
   Arrays.fill(this._states, 0, this._states.length, (byte) 0);
 }
Example #8
0
  public Cedars(String args[]) throws ArchiveException, IOException, HoneycombTestException {

    verbose = false;

    parseArgs(args);
    initHCClient(host);

    // generate lists of random sizes around 30M and 3M
    // sort ascending to allow continuous expansion
    try {
      initRandom();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    sizes = new long[n_files];
    for (int i = 0; i < sizes.length; i++) {
      sizes[i] = MIN_SIZE + (long) (rand.nextDouble() * (double) RANGE);
    }
    Arrays.sort(sizes);

    sizes2 = new long[n_files];
    for (int i = 0; i < sizes2.length; i++) {
      sizes2[i] = MIN_SIZE2 + (long) (rand.nextDouble() * (double) RANGE2);
    }
    Arrays.sort(sizes2);

    sizes3 = new long[n_files];
    for (int i = 0; i < sizes3.length; i++) {
      sizes3[i] = MIN_SIZE3 + (long) (rand.nextDouble() * (double) RANGE3);
    }
    Arrays.sort(sizes3);

    oids = new String[n_files];
    Arrays.fill(oids, null);
    shas = new String[n_files];
    Arrays.fill(shas, null);

    if (out_file != null) {
      try {
        String host = clnthost;
        fo = new FileWriter(out_file, true); // append=true
        flog("#S Cedars [" + host + "] " + new Date() + "\n");
      } catch (Exception e) {
        System.err.println("Opening " + out_file);
        e.printStackTrace();
        System.exit(1);
      }
    }
    Runtime.getRuntime().addShutdownHook(new Thread(new Shutdown(), "Shutdown"));
    doIt();

    done = true;
  }
Example #9
0
  void solve() throws IOException {
    in("knights.in");
    out("knights.out");

    int n = readInt();
    char[][] f = new char[n][n];
    for (int i = 0; i < n; ++i) {
      f[i] = readLine().toCharArray();
    }

    int m = n * n;
    l = new int[m][8];
    for (int i = 0; i < m; ++i) {
      Arrays.fill(l[i], -1);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (((i + j) & 1) == 0 && f[i][j] == '.') {
          for (int k = 0; k < 8; ++k) {
            int ii = i + di[k];
            int jj = j + dj[k];
            if (ii >= 0 && ii < n && jj >= 0 && jj < n && f[ii][jj] == '.') {
              l[i * n + j][k] = ii * n + jj;
            }
          }
        }
      }
    }

    p = new int[m];
    mask = new boolean[m];
    Arrays.fill(p, -1);
    for (int i = 0; i < m; ++i) {
      Arrays.fill(mask, true);
      can(i);
    }

    for (int i = 0; i < m; ++i) {
      if (p[i] != -1) {
        f[i / n][i % n] = 'K';
      }
    }

    for (int i = 0; i < n; ++i) {
      println(String.valueOf(f[i]));
    }

    exit();
  }
Example #10
0
  private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf, int flags)
      throws Exception {
    int rshift = TJ.getRedOffset(pf) * 8;
    int gshift = TJ.getGreenOffset(pf) * 8;
    int bshift = TJ.getBlueOffset(pf) * 8;
    int ashift = alphaOffset[pf] * 8;
    int index, row, col, halfway = 16;

    Arrays.fill(buf, 0);
    for (row = 0; row < h; row++) {
      for (col = 0; col < w; col++) {
        if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col;
        else index = pitch * row + col;
        if (((row / 8) + (col / 8)) % 2 == 0) {
          if (row < halfway) {
            buf[index] |= (255 << rshift);
            buf[index] |= (255 << gshift);
            buf[index] |= (255 << bshift);
          }
        } else {
          buf[index] |= (255 << rshift);
          if (row >= halfway) buf[index] |= (255 << gshift);
        }
        if (ashift >= 0) buf[index] |= (255 << ashift);
      }
    }
  }
Example #11
0
  public void solve() throws IOException {
    int n = in.nextInt();
    int m = in.nextInt();
    graph = new ArrayList[n + 1];
    color = new int[n + 1];
    Arrays.fill(color, 0);

    for (int i = 0; i < m; i++) {
      int from = in.nextInt();
      int to = in.nextInt();
      if (graph[from] == null) {
        graph[from] = new ArrayList<Integer>();
      }
      graph[from].add(to);
    }

    topSort();
    if (hasCycle) {
      out.print(-1);
      return;
    }

    for (Integer anAnswer : answer) {
      out.printf("%d ", anAnswer);
    }
  }
  /**
   * Move the cursor <i>where</i> characters, withough checking the current buffer.
   *
   * @see #where
   * @param where the number of characters to move to the right or left.
   */
  private final void moveInternal(final int where) throws IOException {
    // debug ("move cursor " + where + " ("
    // + buf.cursor + " => " + (buf.cursor + where) + ")");
    buf.cursor += where;

    char c;

    if (where < 0) {
      int len = 0;
      for (int i = buf.cursor; i < buf.cursor - where; i++) {
        if (buf.getBuffer().charAt(i) == '\t') len += TAB_WIDTH;
        else len++;
      }

      char cbuf[] = new char[len];
      Arrays.fill(cbuf, BACKSPACE);
      out.write(cbuf);

      return;
    } else if (buf.cursor == 0) {
      return;
    } else if (mask != null) {
      c = mask.charValue();
    } else {
      printCharacters(buf.buffer.substring(buf.cursor - where, buf.cursor).toCharArray());
      return;
    }

    // null character mask: don't output anything
    if (NULL_MASK.equals(mask)) {
      return;
    }

    printCharacters(c, Math.abs(where));
  }
  public static int[] calculateVectorSpace(BufferedImage image) {
    clusters = createClusters(image);
    int[] vectorSpace = new int[IMAGE_WIDTH * IMAGE_HEIGHT];
    Arrays.fill(vectorSpace, -1);

    boolean refineNeeded = true;
    int loops = 0;
    while (refineNeeded) {
      refineNeeded = false;
      loops++;

      for (int y = 0; y < IMAGE_HEIGHT; y++) {
        for (int x = 0; x < IMAGE_WIDTH; x++) {
          int pixel = image.getRGB(x, y);
          Cluster cluster = getMinCluster(pixel);

          if (vectorSpace[IMAGE_WIDTH * y + x] != cluster.getId()) {
            if (vectorSpace[IMAGE_WIDTH * y + x] != -1) {
              clusters[vectorSpace[IMAGE_WIDTH * y + x]].removePixel(pixel);
            }
            cluster.addPixel(pixel);
            refineNeeded = true;
            vectorSpace[IMAGE_WIDTH * y + x] = cluster.getId();
          }
        }
      }
    }

    System.out.println("Took " + loops + " loops.");
    return vectorSpace;
  }
Example #14
0
  void run() {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), q = in.nextInt();
    int[] v = new int[n], c = new int[n];
    for (int i = 0; i < n; ++i) v[i] = in.nextInt();
    for (int i = 0; i < n; ++i) c[i] = in.nextInt();

    for (int i = 0; i < q; ++i) {
      int a = in.nextInt(), b = in.nextInt();
      long[] dp = new long[n + 1];
      Node[] heap = new Node[2];
      Arrays.fill(dp, -INF);
      for (int j = 0; j < 2; ++j) heap[j] = new Node(-INF, -1);
      for (int j = 0; j < n; ++j) {
        long val = v[j], maxv = val * b;
        int color = c[j];
        maxv = Math.max(dp[color] + val * a, maxv);
        maxv = Math.max(choose(heap, color) + val * b, maxv);
        dp[color] = Math.max(maxv, dp[color]);
        update(heap, dp[color], color);
      }

      long ret = 0;
      for (int j = 1; j <= n; ++j) ret = Math.max(ret, dp[j]);
      out.println(ret);
    }

    out.close();
  }
  public static void main(String[] args) throws Exception {

    /*  BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000);
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int q = Integer.parseInt(s[1]);
    int num[] = new int[n + 1];
    int[] m = new int[3 * n + 1]; // size = 2*n+1
    Arrays.fill(num, -1);
    s = br.readLine().split(" ");
    for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]);
    /// build tree
    maketree(1, 1, n, m, num);

    for (int qq = 1; qq <= q; qq++) {
      s = br.readLine().split(" ");
      int i = Integer.parseInt(s[0]);
      int j = Integer.parseInt(s[1]);
      int ans = query(1, 1, n, m, num, i, j);
      out.write("" + num[ans] + "\n");
      out.flush();
    }
  }
Example #16
0
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		double limit;
		while (test-- > 0) {
			limit = scan.nextDouble();
			n = scan.nextInt();
			V = 0;
			mm = new int[n];
			pp = new float[n];
			for (int i = 0; i < n; i++) {
				mm[i] = scan.nextInt();
				pp[i] = scan.nextFloat();
				V += mm[i];
			}
			dp = new float[V + 1];
			Arrays.fill(dp, 0);
			dp[0] = 1;
			for (int i = 0; i < n; i++)
				ZeroPack(mm[i], 1 - pp[i]);

			for (int i = V; i >= 0; i--)
				if (dp[i] > 1 - limit) {
					out.println(i);
					break;
				}

		}
		out.flush();
		out.close();
	}
 public static void main(String[] args) {
   Scanner inp = new Scanner(System.in);
   int n = inp.nextInt();
   String[] store = new String[n];
   for (int i = 0; i < n; i++) store[i] = inp.next();
   int[] cnt = new int[n];
   Arrays.fill(cnt, 0);
   String str = inp.next();
   for (int j = 0; j < n; j++) {
     int l1 = store[j].length();
     for (int k = 0; k <= (str.length() - l1); k++) {
       if (str.substring(k, k + l1).equals(store[j])) {
         cnt[j] = cnt[j] + 1;
       }
     }
   }
   int y = 0;
   for (int m = 0; m < n; m++) {
     y = Math.max(y, cnt[m]);
   }
   System.out.println(y);
   for (int h = 0; h < n; h++) {
     if (cnt[h] == y) System.out.println(store[h]);
   }
 }
Example #18
0
 public void run() {
   try {
     int n = reader.nextInt();
     int[] a = new int[n];
     for (int i = 0; i < n; ++i) {
       a[i] = reader.nextInt();
     }
     BigInteger[] ways = new BigInteger[4];
     ways[0] = ways[1] = BigInteger.ONE;
     ways[2] = ways[3] = BigInteger.ZERO;
     for (int i = 0; i < n; ++i) {
       BigInteger[] newWays = new BigInteger[4];
       Arrays.fill(newWays, BigInteger.ZERO);
       for (int mask = 0; mask < 4; ++mask) {
         for (int now = 0; now < 2; ++now) {
           int newMask = mask << 1 | now;
           if (Integer.bitCount(newMask) == a[i]) {
             newWays[newMask & 3] = newWays[newMask & 3].add(ways[mask]);
           }
         }
       }
       ways = newWays;
     }
     BigInteger answer = ways[0].add(ways[2]);
     writer.println(answer);
   } catch (IOException ex) {
   }
   writer.close();
 }
  private static void solve(int[][] points) {
    int N = points.length;
    int W = (1 << N);
    int[][] dp = new int[N][W];
    int[][] masks = new int[N][N];
    int[][] areas = new int[N][N];
    makeMasksAndAreas(points, masks, areas);

    for (int i = 0; i < N; i++) {
      Arrays.fill(dp[i], Integer.MAX_VALUE);
    }

    dp[0][0] = 0;

    for (int i = 1; i < N; i++) {
      for (int state = 0; state < W; state++) {
        if (dp[i - 1][state] == Integer.MAX_VALUE) continue;
        for (int a = 0; a < N; a++) {
          for (int b = a + 1; b < N; b++) {
            int mask = masks[a][b];
            if ((mask | state) == state) continue;

            dp[i][mask | state] = Math.min(dp[i][mask | state], dp[i - 1][state] + areas[a][b]);
          }
        }
      }
    }

    int res = Integer.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      res = Math.min(res, dp[i][W - 1]);
    }

    System.out.println(res);
  }
 public void fill(final int fromIndex, final int toIndex, final short val) {
   if (toIndex > this._pos) {
     this.ensureCapacity(toIndex);
     this._pos = toIndex;
   }
   Arrays.fill(this._data, fromIndex, toIndex, val);
 }
Example #21
0
 // pretty print Matrix(2D array of doubles)
 public static String pprint(double[][] arr,DecimalFormat dformat) {
   int colDim = 0;
   for( double[] line : arr )
     colDim = Math.max(colDim, line.length);
   StringBuilder sb = new StringBuilder();
   int max_width = 0;
   int[] ilengths = new int[colDim];
   Arrays.fill(ilengths, -1);
   for( double[] line : arr ) {
     for( int c = 0; c < line.length; ++c ) {
       double d = line[c];
       String dStr = dformat.format(d);
       if( dStr.indexOf('.') == -1 ) dStr += ".0";
       ilengths[c] = Math.max(ilengths[c], dStr.indexOf('.'));
       int prefix = (d >= 0 ? 1 : 2);
       max_width = Math.max(dStr.length() + prefix, max_width);
     }
   }
   for( double[] line : arr ) {
     for( int c = 0; c < line.length; ++c ) {
       double d = line[c];
       String dStr = dformat.format(d);
       if( dStr.indexOf('.') == -1 ) dStr += ".0";
       for( int x = dStr.indexOf('.'); x < ilengths[c] + 1; ++x )
         sb.append(' ');
       sb.append(dStr);
       if( dStr.indexOf('.') == -1 ) sb.append('.');
       for( int i = dStr.length() - Math.max(0, dStr.indexOf('.')); i <= 5; ++i )
         sb.append('0');
     }
     sb.append("\n");
   }
   return sb.toString();
 }
Example #22
0
 public void Init() {
   fail[0] = 0;
   flag[0] = 0;
   Arrays.fill(ch[0], 0);
   sz = 1;
   for (int i = 0; i < DIC.length(); i++) ID[DIC.charAt(i)] = i;
   CD = DIC.length();
 }
Example #23
0
  public void reset(FeatureVector wv) {
    this.iter = 0;

    Arrays.fill(dir, 0);
    Arrays.fill(this.steepestDescDir, 0);

    Arrays.fill(w, 0);
    Arrays.fill(newW, 0);

    Arrays.fill(grad, 0);
    Arrays.fill(newGrad, 0);

    for (int i = 0; i < wv.size(); ++i) {
      int fid = wv.idByIndex(i);
      double v = wv.valueByIndex(i);

      w[fid - 1] = v;
    }
    lossFunction.eval(w, grad);

    Arrays.fill(alphas, 0);
    this.sList.clear();
    this.yList.clear();
    this.roList.clear();

    this.prevVals.clear();
    this.value = evalL1();
  }
 private final void printCharacters(final char c, final int num) throws IOException {
   if (num == 1) {
     printCharacter(c);
   } else {
     char[] chars = new char[num];
     Arrays.fill(chars, c);
     printCharacters(chars);
   }
 }
Example #25
0
  /** Make a heatmap blocks from given window indexes, stop not included. */
  public void sumHeatMapBlocks(int startIndex, int stopIndex) {
    // create arrays of float, one per base to hold sums
    // windows are sorted by start and length
    int startBase = windows[startIndex].getStart();
    int stopBase = findMaxStop(startIndex, stopIndex);

    int numBases = 1 + stopBase - startBase;
    float[] sums = new float[numBases];

    // load max arrays with max scores
    // for each window
    for (int i = startIndex; i < stopIndex; i++) {
      float score = windows[i].getScore();
      int baseIndex = windows[i].getStart() - startBase;
      int length = windows[i].getStop() - windows[i].getStart() + baseIndex + 1;
      for (int j = baseIndex; j < length; j++) sums[j] += score;
    }

    // build blocks
    // open first block
    // set zero mark
    int previousBase = startBase - 1;
    if (previousBase < 0) previousBase = 0;
    add(previousBase, 0);
    // set block value
    float blockValue = sums[0];
    add(startBase, blockValue);

    // advance each base opening and closing blocks
    for (int i = 1; i < numBases; i++) {
      float testValue = sums[i];
      if (testValue != blockValue) {
        // close old
        add(i - 1 + startBase, blockValue);
        // open new
        blockValue = testValue;
        add(i + startBase, blockValue);
      }
    }
    // close last block
    add(numBases - 2 + startBase, blockValue);
    add(numBases - 1 + startBase, 0);

    // make merged filtered bed file?
    if (bedOut != null) {
      boolean[] falseMask = new boolean[sums.length];
      Arrays.fill(falseMask, true);
      for (int i = 0; i < sums.length; i++) if (sums[i] >= threshold) falseMask[i] = false;
      int[][] blocks = ExportIntergenicRegions.fetchFalseBlocks(falseMask, 0, 0);
      // print bed file
      for (int i = 0; i < blocks.length; i++) {
        bedOut.println(
            chromosome + "\t" + (startBase + blocks[i][0]) + "\t" + (startBase + blocks[i][1]));
      }
    }
  }
  /**
   * Output the specified character to the output stream without manipulating the current buffer.
   */
  private final void printCharacter(final int c) throws IOException {
    if (c == '\t') {
      char cbuf[] = new char[TAB_WIDTH];
      Arrays.fill(cbuf, ' ');
      out.write(cbuf);
      return;
    }

    out.write(c);
  }
Example #27
0
 public static void solve() {
   int cases = scan.nextInt();
   scan.nextLine();
   for (int caze = 1; caze <= cases; caze++) {
     out.print("Case #" + caze + ": ");
     for (int i = 0; i < MAX; i++) Arrays.fill(memo[i], -1);
     str = scan.nextLine().toCharArray();
     out.println(go(0, str.length) ? "YES" : "NO");
   }
 }
 /**
  * Creates a new <code>TIntIntHashMap</code> instance containing all of the entries in the map
  * passed in.
  *
  * @param map a <tt>TIntIntMap</tt> that will be duplicated.
  */
 public TIntIntHashMap(TIntIntMap map) {
   super(map.size());
   if (map instanceof TIntIntHashMap) {
     TIntIntHashMap hashmap = (TIntIntHashMap) map;
     this._loadFactor = hashmap._loadFactor;
     this.no_entry_key = hashmap.no_entry_key;
     this.no_entry_value = hashmap.no_entry_value;
     //noinspection RedundantCast
     if (this.no_entry_key != (int) 0) {
       Arrays.fill(_set, this.no_entry_key);
     }
     //noinspection RedundantCast
     if (this.no_entry_value != (int) 0) {
       Arrays.fill(_values, this.no_entry_value);
     }
     setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor));
   }
   putAll(map);
 }
Example #29
0
 public Charlie(int n, int[] F) {
   this.n = n;
   this.F = F;
   this.S = new int[n];
   this.U = new boolean[n];
   Arrays.fill(U, true);
   for (int i = 0; i < n; i++) {
     U[F[i]] = false;
   }
 }
  /**
   * Redraw the rest of the buffer from the cursor onwards. This is necessary for inserting text
   * into the buffer.
   *
   * @param clear the number of characters to clear after the end of the buffer
   */
  private final void drawBuffer(final int clear) throws IOException {
    // debug ("drawBuffer: " + clear);
    char[] chars = buf.buffer.substring(buf.cursor).toCharArray();
    if (mask != null) Arrays.fill(chars, mask.charValue());

    printCharacters(chars);

    clearAhead(clear);
    back(chars.length);
    flushConsole();
  }