protected void pushDownRoot(int root) { // pre: 0<=root<size // post: moves node at index root down to appropiate position in subtree int heapSize = data.size(); E value = data.get(root); while (root < heapSize) { int childpos = left(root); if (childpos < heapSize) { if ((right(root) < heapSize) && ((data.get(childpos + 1)).compareTo(data.get(childpos)) < 0)) { childpos++; } // Assert: childpos indexes smaller of two children if ((data.get(childpos)).compareTo(value) < 0) { data.set(root, data.get(childpos)); root = childpos; // keep moving down } else { data.set(root, value); return; } } else { data.set(root, value); return; } } }
/** * Compute a distance-2 coloring of a bipartite graph G_b restricted to required edges * * <p>Input: - G_b bipartite graph with required egdes given as weights edge_weight - V contained * vertices are colored in the given ordering v_1, ..., v_n * * <p>Output: - G_b bipartite graph with colors as weights vertex_color */ public static int PartialD2ColoringRestricted(GraphModel g, Vector<Integer> V) { Vector<Integer> N2 = new Vector<>(); Vector<Integer> forbidden = new Vector<>(g.numOfVertices()); for (int i = 0; i < g.numOfVertices(); i++) forbidden.add(-1); for (int v : V) g.getVertex(v).setColor(0); for (int v : V) { forbidden.set(0, v); if (IncidentToReqEdge(g, v)) { N2 = Neighbors.N_2_restricted(g, v); for (int n2 : N2) { if (g.getVertex(n2).getColor() > 0) { forbidden.set(g.getVertex(n2).getColor(), v); } } for (int i = 0; i < forbidden.size(); i++) { if (forbidden.get(i) != v) { g.getVertex(v).setColor(i); break; } } } else { g.getVertex(v).setColor(0); } } return getNumOfCols(g); }
public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); StringTokenizer st; t = Integer.parseInt(br.readLine()); while (t-- > 0) { st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); S = Integer.parseInt(st.nextToken()); T = Integer.parseInt(st.nextToken()); // build graph AdjList = new Vector<Vector<IntegerPair>>(); for (i = 0; i < n; i++) AdjList.add(new Vector<IntegerPair>()); while (m-- > 0) { st = new StringTokenizer(br.readLine()); a = Integer.parseInt(st.nextToken()); b = Integer.parseInt(st.nextToken()); w = Integer.parseInt(st.nextToken()); AdjList.get(a).add(new IntegerPair(b, w)); // bidirectional AdjList.get(b).add(new IntegerPair(a, w)); } // SPFA from source S // initially, only S has dist = 0 and in the queue Vector<Integer> dist = new Vector<Integer>(); for (i = 0; i < n; i++) dist.add(INF); dist.set(S, 0); Queue<Integer> q = new LinkedList<Integer>(); q.offer(S); Vector<Boolean> in_queue = new Vector<Boolean>(); for (i = 0; i < n; i++) in_queue.add(false); in_queue.set(S, true); while (!q.isEmpty()) { int u = q.peek(); q.poll(); in_queue.set(u, false); for (j = 0; j < AdjList.get(u).size(); j++) { // all outgoing edges from u int v = AdjList.get(u).get(j).first(), weight_u_v = AdjList.get(u).get(j).second(); if (dist.get(u) + weight_u_v < dist.get(v)) { // if can relax dist.set(v, dist.get(u) + weight_u_v); // relax if (!in_queue.get(v)) { // add to the queue only if it's not in the queue q.offer(v); in_queue.set(v, true); } } } } pr.printf("Case #%d: ", caseNo++); if (dist.get(T) != INF) pr.printf("%d\n", dist.get(T)); else pr.printf("unreachable\n"); } pr.close(); }
@Override public void setValueAt(Object aValue, int row, int column) { if (aValue instanceof Boolean && column == 0) { Vector rowData = (Vector) getDataVector().get(row); rowData.set(0, (boolean) aValue); fireTableCellUpdated(row, column); } if (column == 4) { Vector rowData = (Vector) getDataVector().get(row); rowData.set(4, aValue); fireTableCellUpdated(row, column); } if (column == 5) { Vector rowData = (Vector) getDataVector().get(row); rowData.set(5, aValue); fireTableCellUpdated(row, column); } if (column == 6) { Vector rowData = (Vector) getDataVector().get(row); rowData.set(6, aValue); fireTableCellUpdated(row, column); } if (column == 7) { Vector rowData = (Vector) getDataVector().get(row); rowData.set(7, aValue); fireTableCellUpdated(row, column); } }
/** * Get the format index that matches the given format string, creating a new format entry if * required. Aliases text to the proper format as required. * * @param pFormat string matching a built in format * @return index of format. */ public short getFormat(String pFormat) { // Normalise the format string String format; if (pFormat.toUpperCase(Locale.ROOT).equals("TEXT")) { format = "@"; } else { format = pFormat; } // Merge in the built in formats if we haven't already if (!_movedBuiltins) { for (int i = 0; i < _builtinFormats.length; i++) { ensureFormatsSize(i); if (_formats.get(i) == null) { _formats.set(i, _builtinFormats[i]); } else { // The workbook overrides this default format } } _movedBuiltins = true; } // See if we can find it for (int i = 0; i < _formats.size(); i++) { if (format.equals(_formats.get(i))) { return (short) i; } } // We can't find it, so add it as a new one short index = _workbook.getFormat(format, true); ensureFormatsSize(index); _formats.set(index, format); return index; }
@Override public boolean onContextItemSelected(MenuItem item) { int posn = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).position; Codec c = codecs.elementAt(posn); if (item.getItemId() == MENU_UP) { if (posn == 0) return super.onContextItemSelected(item); Codec tmp = codecs.elementAt(posn - 1); codecs.set(posn - 1, c); codecs.set(posn, tmp); } else if (item.getItemId() == MENU_DOWN) { if (posn == codecs.size() - 1) return super.onContextItemSelected(item); Codec tmp = codecs.elementAt(posn + 1); codecs.set(posn + 1, c); codecs.set(posn, tmp); } PreferenceScreen ps = getPreferenceScreen(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); String v = ""; SharedPreferences.Editor e = sp.edit(); for (Codec d : codecs) v = v + d.number() + " "; e.putString(Settings.PREF_CODECS, v); e.commit(); ps.removeAll(); addPreferences(ps); return super.onContextItemSelected(item); }
/** * Add a directory entry. * * @param nameExt * @throws IOException */ protected synchronized FatDirEntry addFatFile(String nameExt) throws IOException { if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException("addFile in readonly filesystem"); } if (getFatEntry(nameExt) != null) { throw new IOException("File already exists" + nameExt); } final FatDirEntry newEntry = new FatDirEntry(this, splitName(nameExt), splitExt(nameExt)); int size = entries.size(); for (int i = 0; i < size; i++) { FatBasicDirEntry e = entries.get(i); if (e == null) { entries.set(i, newEntry); setDirty(); flush(); return newEntry; } } int newSize = size + 512 / 32; if (canChangeSize(newSize)) { entries.ensureCapacity(newSize); setDirty(); flush(); return newEntry; } throw new IOException("Directory is full"); }
public void convertCaptureTimes() { double start = ((Double) startCaptureTimes.get(0)).doubleValue(); for (int x = 0; x < startCaptureTimes.size(); x++) { startCaptureTimes.set( x, new Double(((Double) startCaptureTimes.get(x)).doubleValue() - start)); stopCaptureTimes.set(x, new Double(((Double) stopCaptureTimes.get(x)).doubleValue() - start)); // print("Captures Times" + startCaptureTimes.get(x) + " " + stopCaptureTimes.get(x)); } }
/** * Moves the layer at <code>index</code> up one in the vector. * * @param index the index of the layer to swap up */ public void swapLayerUp(int index) { if (index + 1 == layers.size()) { throw new RuntimeException("Can't swap up when already at the top."); } MapLayer hold = layers.get(index + 1); layers.set(index + 1, getLayer(index)); layers.set(index, hold); }
/** * Moves the layer at <code>index</code> down one in the vector. * * @param index the index of the layer to swap down */ public void swapLayerDown(int index) { if (index - 1 < 0) { throw new RuntimeException("Can't swap down when already at the bottom."); } MapLayer hold = layers.get(index - 1); layers.set(index - 1, getLayer(index)); layers.set(index, hold); }
public static boolean StarBicoloringDynamicOrdering( GraphModel g, Vector<Integer> V_r, Vector<Integer> V_c, int Ordering) { Vector<Integer> forbiddenColors = new Vector<>(V_r.size()); for (int i = 0; i < V_r.size(); i++) forbiddenColors.add(-1); Vector<Integer> Vertices = new Vector<>(V_r.size() + V_c.size()); // GraphModel gg = g.getCopy(); for (int i = 0; i < V_r.size(); i++) { Vertices.add(g.getVertex(i).getId()); } for (int i = 0; i < V_c.size(); i++) { Vertices.add(g.getVertex(i).getId()); } if (Ordering != 0) { if (Ordering == 1) { Vertices = OrderingHeuristics.LFO(g, Vertices); } if (Ordering == 2) { Vertices = OrderingHeuristics.SLO(g, Vertices); } if (Ordering == 3) { Vertices = OrderingHeuristics.IDO(g, Vertices); } } for (int v : Vertices) { if (g.getVertex(v).getColor() != 0) { forbiddenColors.set(0, v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) forbiddenColors.set(x.getColor(), v); } } else { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getColor(), v); } } } } } } } } for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) g.getVertex(v).setColor(i); } } return true; }
/** * Verifică daca mutarea este ilegală. Dacă este ilegală, întoarce motivul. Dacă întoarce <code> * "legal"</code>. înseamnă mutarea este legală. * * @param mutare mutarea care trebuie analizată * @param i indicele jucătorului * @return motivul pentru care mutarea este ilegală, sau <code>"legal"</code> dacă-i legală */ protected String esteMutareIlegala(Mutare mutare, int i) { String motiv = mutare.verificareLegalitate(tipJoc); if (!motiv.equals("legal")) return motiv; int deLuat = numarDeLuat(); if (deLuat == 0) { if (mutare.numarDeCarti > 1) return "Nu ai voie să iei mai mult de o carte dacă nu ai fost pedepsit!"; } else { boolean raspunde = false; if (mutare.cartiDePus != null) { if (mutare.cartiDePus[0].getNumar() <= 3) raspunde = true; // este jocher, 2 sau 3 if (tipJoc.cuStopare && mutare.cartiDePus[0].getNumar() == tipJoc.carteaDeStopare) raspunde = true; } if (deLuat == mutare.numarDeCarti) raspunde = true; if (mutare.staTura) raspunde = true; if (!raspunde) return "Ai fost pedepsit și în loc să dai mai departe sau să iei ai făcut altceva!"; } int deStat = tureDeStat(); if (deStat > 0) { boolean raspunde = false; if (mutare.cartiDePus != null && mutare.cartiDePus[0].getNumar() == tipJoc.carteaDeStatTura) raspunde = true; if (mutare.staTura) { raspunde = true; // dacă el deja stă trebuie să pice următorului if (tureDeStat.get(i) == 0) { tureDeStat.set(i, deStat); adaugaCaPrimaTura(mutari.size()); } } if (!raspunde) return "Trebuie să stai tura, dar n-ai dat mai departe și nici n-ai stat!"; } if (mutare.staTura) { if (tureDeStat.get(i) == 0) return "Ai stat tura fără motiv!"; } else { if (tureDeStat.get(i) > 0) { System.out.println(tureDeStat.get(i)); return "Trebuie să stai tura și n-ai stat"; } } if (tureDeStat.get(i) > 0) tureDeStat.set(i, tureDeStat.get(i) - 1); // dacă nu este o carte specială trebuie să se potrivească peste celelalte cărți. // trebuie verificat dacă chiar are cărțile pe care vrea să le pună if (!contineCartile(mutare.cartiDePus, cartiJucatori.get(i))) return "Nu ai cărțile pe care vrei să le pui jos!"; mutari.add(mutare); return "legal"; }
/** * Sets the first two entries '.' and '..' in the directory * * @param parentCluster */ protected void initialize(long myCluster, long parentCluster) { FatDirEntry e = new FatDirEntry(this, ".", ""); entries.set(0, e); e.setFlags(FatConstants.F_DIRECTORY); e.setStartCluster((int) myCluster); e = new FatDirEntry(this, "..", ""); entries.set(1, e); e.setFlags(FatConstants.F_DIRECTORY); e.setStartCluster((int) parentCluster); }
// Sort the table of nodes in croissant order void sortNodes() { Node bufI = letters.get(0); for (int i = 0; i < letters.size() - 1; i++) { for (int j = i + 1; j < letters.size(); j++) { if (letters.get(j).compareTo(letters.get(i)) < 0) { bufI = letters.get(j); letters.set(j, letters.get(i)); letters.set(i, bufI); } } } }
protected void percolateUp(int leaf) { // pre: 0<=leaf<size // post: moves node at index lead up to appropiate position int parent = parent(leaf); E value = data.get(leaf); while (leaf > 0 && (value.compareTo(data.get(parent)) < 0)) { data.set(leaf, data.get(parent)); leaf = parent; parent = parent(leaf); } data.set(leaf, value); }
/** * Read the contents of this directory from the given byte array * * @param src */ protected synchronized void read(byte[] src) { int size = entries.size(); for (int i = 0; i < size; i++) { int index = i * 32; if (src[index] == 0) { entries.set(i, null); } else { FatBasicDirEntry entry = FatDirEntry.fatDirEntryFactory(this, src, index); entries.set(i, entry); } } }
// 修改人员 public void updPerson(Person p) { for (int i = 0; i < JTableModel.rowdatas.size(); i++) { Vector v1 = JTableModel.rowdatas.get(i); int id = (Integer) v1.get(0); if (p.getIds() == id) { // v1.set(0, p.getIds()); v1.set(1, p.getName()); v1.set(2, p.getAge()); v1.set(3, p.getSex()); } } }
public static void main(String[] args) throws Exception { int V, E, s, a, b, w; File f = new File("in_06.txt"); Scanner sc = new Scanner(f); V = sc.nextInt(); E = sc.nextInt(); s = sc.nextInt(); AdjList.clear(); for (int i = 0; i < V; i++) { Vector<IntegerPair> Neighbor = new Vector<IntegerPair>(); AdjList.add(Neighbor); // add neighbor list to Adjacency List } for (int i = 0; i < E; i++) { a = sc.nextInt(); b = sc.nextInt(); w = sc.nextInt(); AdjList.get(a).add(new IntegerPair(b, w)); // first time using weight } // as an example, we start from this source (see Figure 1.15) Vector<Integer> dist = new Vector<Integer>(); dist.addAll(Collections.nCopies(V, INF)); dist.set(s, 0); // Bellman Ford routine for (int i = 0; i < V - 1; i++) // relax all E edges V-1 times, O(V) for (int u = 0; u < V; u++) { // these two loops = O(E) Iterator it = AdjList.get(u).iterator(); while (it.hasNext()) { // relax these edges IntegerPair v = (IntegerPair) it.next(); dist.set(v.first(), Math.min(dist.get(v.first()), dist.get(u) + v.second())); } } boolean negative_cycle_exist = false; for (int u = 0; u < V; u++) { // one more pass to check Iterator it = AdjList.get(u).iterator(); while (it.hasNext()) { // relax these edges IntegerPair v = (IntegerPair) it.next(); if (dist.get(v.first()) > dist.get(u) + v.second()) // should be false, but if possible negative_cycle_exist = true; // then negative cycle exists! } } System.out.printf("Negative Cycle Exist? %s\n", negative_cycle_exist ? "Yes" : "No"); if (!negative_cycle_exist) for (int i = 0; i < V; i++) System.out.printf("SSSP(%d, %d) = %d\n", s, i, dist.get(i)); }
public static boolean StarBicoloringRestricted( GraphModel g, Vector<Integer> V_r, Vector<Integer> V_c) { Vector<Integer> forbiddenColors = new Vector<>(V_r.size()); for (int i = 0; i < V_r.size(); i++) forbiddenColors.add(-1); Vector<Integer> Vertices = new Vector<>(V_r.size() + V_c.size()); // GraphModel gg = g.getCopy(); for (int v_r : V_r) Vertices.add(v_r); for (int v_c : V_c) Vertices.add(v_c); for (int v : Vertices) { if (g.getVertex(v).getColor() != 0) { forbiddenColors.set(0, v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { if (g.getEdge(x, w).getWeight() == 1 || g.getEdge(w, g.getVertex(v)).getWeight() == 1) { forbiddenColors.set(x.getColor(), v); } } } } else { for (Vertex x : g.getNeighbors(w)) { System.out.println(" jez " + g.getEdge(x, w).getWeight()); if (g.getEdge(x, w).getWeight() == 1) { if (x.getColor() > 0) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getColor(), v); } } } } } } } } } for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) { g.getVertex(v).setColor(i); } } } return true; }
/** Swaps the tile sets at the given indices. */ public void swapTileSets(int index0, int index1) { if (index0 == index1) return; TileSet set = tilesets.get(index0); tilesets.set(index0, tilesets.get(index1)); tilesets.set(index1, set); if (index0 > index1) { int temp = index1; index1 = index0; index0 = temp; } fireTilesetsSwapped(index0, index1); }
/** Remet les horaires par ordre chronologique dans la liste */ public void trierHoraireChronologique() { Horaire horaireTemp = new Horaire(); for (int i = 0; i < listeHoraires.size() - 1; i++) { for (int j = i + 1; j < listeHoraires.size(); j++) { if ((getHoraire(i).getHeure() > getHoraire(j).getHeure()) || (getHoraire(i).getHeure() == getHoraire(j).getHeure() && getHoraire(i).getMinute() > getHoraire(j).getMinute())) { horaireTemp = getHoraire(i); listeHoraires.set(i, getHoraire(j)); listeHoraires.set(j, horaireTemp); } } } }
/** * PDF has a wacky grammar which must be a legacy of PostScript's postfix syntax. A keyword of R * means that the two previous objects are really part of an indirect object reference. This means * that when a vector of objects is complete, it has to be read backwards so that indirect object * references can be collapsed out. In the case of a dictionary, this has to be done before the * content can be interpreted as key-value pairs. */ private void collapseObjectVector(Vector v) throws PdfException { for (int i = v.size() - 1; i >= 2; i--) { PdfObject obj = (PdfObject) v.elementAt(i); if (obj instanceof PdfSimpleObject) { Token tok = ((PdfSimpleObject) obj).getToken(); if (tok instanceof Keyword) { if ("R".equals(((Keyword) tok).getValue())) { // We're in the key of 'R'. The two previous tokens // had better be Numerics. Three objects in the Vector // are replaced by one. try { PdfSimpleObject nobj = (PdfSimpleObject) v.elementAt(i - 2); Numeric ntok = (Numeric) nobj.getToken(); int objNum = ntok.getIntegerValue(); nobj = (PdfSimpleObject) v.elementAt(i - 1); ntok = (Numeric) nobj.getToken(); int genNum = ntok.getIntegerValue(); v.set(i - 2, new PdfIndirectObj(objNum, genNum, _objectMap)); v.removeElementAt(i); v.removeElementAt(i - 1); i -= 2; } catch (Exception e) { throw new PdfMalformedException("Malformed indirect object reference"); } } } } } }
private Object prepareActionData(IEvent event) throws Exception { ViewCertificateEvent certEvent = (ViewCertificateEvent) event; Vector certList = null; try { String password = certEvent.getPassword(); Boolean isFile = certEvent.isFile(); if (isFile != null && isFile.booleanValue()) { File certFile = FileUtil.getFile(IPathConfig.PATH_TEMP, _userID + "/in/", certEvent.getName()); certList = getManager().getX500NamesAndCertDetail(certFile.getAbsolutePath(), password); certFile.delete(); } else { certList = getManager().getX500NamesAndCertDetail(certEvent.getUId()); } // TWX 26072006 Convert the serial number into hex format byte[] serialNumInByte = (byte[]) certList.get(2); certList.set(2, convertByteToHex(serialNumInByte)); } catch (Exception aex) { throw aex; } return certList; }
/** * Set a JsonValue into this json array on specific index. * * @param idx * @param value */ public void set(int idx, JsonValue value) { // Change to ARRAY_VALUE changeType(VALUE_TYPE.ARRAY_VALUE); extendArray(idx); mArrayValue.set(idx, value); }
public void deleteResponseHandler(final ResponseHandler handler) { final int index = mResponseHandlers.indexOf(handler); if (index != -1) { // set value to null to enable garbage collection, but don't remove it to keep indexes mResponseHandlers.set(index, null); } }
public static void main(String[] args) { // TODO Auto-generated method stub Vector<String> vec = new Vector<String>(); vec.add("홍길동"); // 0 vec.add("이순신"); // 3 vec.add("을지문덕"); // 4 vec.add(1, "심청이"); // 2 vec.add(1, "춘향이"); // 1 vec.addElement("이산"); // 5 for (String name : vec) { System.out.println(name); } System.out.println("삭제후...."); vec.removeElementAt(0); for (String name : vec) { System.out.println(name); } vec.set(1, "박문수"); for (String name : vec) { System.out.println(name); } vec.setElementAt("강감찬", 1); for (String name : vec) { System.out.println(name); } System.out.println("출력..."); for (int i = 0; i < vec.size(); i++) { String name = vec.get(i); // elementAt(i) System.out.println(name); } // 전체 삭제 vec.removeAllElements(); // clear() System.out.println("전체 인원:" + vec.size()); }
public void updateTable(DownloadBean bean) { Vector<DownloadBean> data = getDownloadList(); data.set(data.indexOf(bean), bean); refreshTable(data); }
public void convertNumbers(double length) { /// convert Down by percentage for (int x = 0; x < soundList.size(); x++) { SoundData sd = (SoundData) soundList.get(x); sd.worldTime *= length / totalLength; sd.duration *= length / totalLength; sd.clippedDuration *= length / totalLength; } for (int x = 0; x < startCaptureTimes.size(); x++) { double d = ((Double) startCaptureTimes.get(x)).doubleValue(); startCaptureTimes.set(x, new Double(d * length / totalLength)); d = ((Double) stopCaptureTimes.get(x)).doubleValue(); stopCaptureTimes.set(x, new Double(d * length / totalLength)); } }
Woman ExtractMax() { Woman maxV = A.get(1); A.set(1, A.get(BinaryHeapSize)); BinaryHeapSize--; // virtual decrease shiftDown(1); return maxV; }
private void interpolateSegments(Vector<Double> f0) { int i, n, interval; double slope; // check where there are zeros and interpolate int[] index = new int[2]; double[] value = new double[2]; index[0] = 0; value[0] = 0.0; for (i = 0; i < f0.size(); i++) { if (f0.get(i) > 0.0) { index[1] = i; value[1] = f0.get(i); interval = index[1] - index[0]; if (interval > 1) { // System.out.format("Interval to interpolate index[0]=%d // index[1]=%d\n",index[0],index[1]); slope = ((value[1] - value[0]) / interval); for (n = index[0]; n < index[1]; n++) { double newVal = (slope * (n - index[0])) + value[0]; f0.set(n, newVal); // System.out.format(" n=%d value:%.1f\n",n,newVal); } } index[0] = index[1]; value[0] = value[1]; } } }