public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(System.out, true); for (; ; ) { int n = in.nextInt(); if (n == 0) break; int[] arr1 = new int[n]; for (int i = 0; i < n; i++) arr1[i] = in.nextInt(); int m = in.nextInt(); int[] arr2 = new int[m]; for (int i = 0; i < m; i++) arr2[i] = in.nextInt(); int idx1 = 0, idx2 = 0, sum1 = 0, sum2 = 0, sum = 0; for (; ; ) { sum1 += arr1[idx1]; while (idx2 < m && arr1[idx1] > arr2[idx2]) sum2 += arr2[idx2++]; if (idx2 == m) { idx1++; break; } if (arr1[idx1] == arr2[idx2]) { sum2 += arr2[idx2++]; sum += Math.max(sum1, sum2); sum1 = sum2 = 0; } idx1++; if (idx1 == n) break; } while (idx1 < n) sum1 += arr1[idx1++]; while (idx2 < m) sum2 += arr2[idx2++]; sum += Math.max(sum1, sum2); out.println(sum); } }
public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int t = in.nextInt(); TreeMap<Long, Long> tmap = new TreeMap<>(); long res = 0; while (t-- > 0) { res = 0; int n = in.nextInt(); long m = in.nextLong(); tmap.clear(); long[] arr = new long[n]; res = in.nextLong(); arr[0] = res % m; res = Long.MIN_VALUE; tmap.put(arr[0], arr[0]); for (int i = 1; i < arr.length; i++) { arr[i] = in.nextLong(); arr[i] %= m; arr[i] += arr[i - 1]; arr[i] %= m; if (tmap.higherEntry(arr[i]) == null) { res = Math.max(res, arr[i]); tmap.put(arr[i], arr[i]); continue; } long val = tmap.higherEntry(arr[i]).getValue(); res = Math.max(res, (arr[i] - val + m) % m); tmap.put(arr[i], arr[i]); } System.out.println(res); } }
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(); }
/** * Updates all the statistics for the current itemset. * * @param predictedClassification Distribution of class values predicted for the itemset. * @param itemset The itemset. * @param nClasses The number of classes. */ private void updateStats(double[] predictedClassification, Itemset itemset, int nClasses) { int actualClass = (int) itemset.getClassValue(); if (!itemset.classIsMissing()) { updateMargins(predictedClassification, actualClass, nClasses); // Determine the predicted class (doesn't detect multiple classifications) int predictedClass = -1; double bestProb = 0.0; for (int i = 0; i < nClasses; i++) { if (predictedClassification[i] > bestProb) { predictedClass = i; bestProb = predictedClassification[i]; } } // Update counts when no class was predicted if (predictedClass < 0) { return; } double predictedProb = Math.max(Double.MIN_VALUE, predictedClassification[actualClass]); double priorProb = Math.max(Double.MIN_VALUE, priorsProbabilities[actualClass] / classPriorsSum); } }
private long calculateExpiry( URLConnection urlConnection, long request_time, UrlConnectionExpiryCalculator urlConnectionExpiryCalculator) { if ("no-cache".equals(urlConnection.getHeaderField("Pragma"))) { return 0L; } final String cacheControl = urlConnection.getHeaderField("Cache-Control"); if (cacheControl != null) { if (cacheControl.indexOf("no-cache") != -1) { return 0L; } final int max_age = getMaxAge(cacheControl); if (-1 != max_age) { final long response_time = System.currentTimeMillis(); final long apparent_age = Math.max(0, response_time - urlConnection.getDate()); final long corrected_received_age = Math.max(apparent_age, urlConnection.getHeaderFieldInt("Age", 0) * 1000L); final long response_delay = response_time - request_time; final long corrected_initial_age = corrected_received_age + response_delay; final long creation_time = response_time - corrected_initial_age; return max_age * 1000L + creation_time; } } final long explicitExpiry = urlConnection.getHeaderFieldDate("Expires", -1L); if (explicitExpiry != -1L) { return explicitExpiry; } return urlConnectionExpiryCalculator == null ? 0L : urlConnectionExpiryCalculator.calculateExpiry(urlConnection); }
/** * Get the distance between a point and this cuboid. * * @param pos * @return */ public double distance(Vector pos) { Vector max = origin.add(new Vector(width, height, length)); int closestX = Math.max(origin.getBlockX(), Math.min(max.getBlockX(), pos.getBlockX())); int closestY = Math.max(origin.getBlockY(), Math.min(max.getBlockY(), pos.getBlockY())); int closestZ = Math.max(origin.getBlockZ(), Math.min(max.getBlockZ(), pos.getBlockZ())); return pos.distance(new Vector(closestX, closestY, closestZ)); }
public static void main(String[] args) { FastScanner in = new FastScanner(System.in); int n = in.nextInt(); int[] s = new int[n + 5]; int[] s2 = new int[n + 5]; for (int i = 1; i <= n; i++) { s[i] = in.nextInt(); s2[n - i + 1] = s[i]; } int[] stack = new int[n + 5]; int size = 0; int answer = 0; for (int i = 1; i <= n; i++) { while (size > 0 && stack[size - 1] < s[i]) size--; stack[size++] = s[i]; if (size >= 2) answer = Math.max(answer, stack[size - 1] ^ stack[size - 2]); } size = 0; for (int i = 1; i <= n; i++) { while (size > 0 && stack[size - 1] < s2[i]) size--; stack[size++] = s2[i]; if (size >= 2) answer = Math.max(answer, stack[size - 1] ^ stack[size - 2]); } System.out.println(answer); }
public static void doIt() throws Exception { Scanner scanner = new Scanner(System.in); Integer currentBalance = scanner.nextInt(); int removeLast, removePenultimate; StringBuffer buf = new StringBuffer(); ArrayList<Character> chars = new ArrayList<Character>(); for (Character c : currentBalance.toString().toCharArray()) chars.add(c); ArrayList<Character> c1 = (ArrayList<Character>) chars.clone(); c1.remove(c1.size() - 1); for (Character cc : c1) buf.append(cc); removeLast = new Integer(buf.toString()); buf = new StringBuffer(); ArrayList<Character> c2 = (ArrayList<Character>) chars.clone(); c2.remove(c2.size() - 2); for (Character cc : c2) buf.append(cc); removePenultimate = new Integer(buf.toString()); System.out.println(Math.max(currentBalance, Math.max(removeLast, removePenultimate))); }
public int getCount(int[] B, String operators) { long INF = 1L << 50; long min = 1; long max = INF; for (int i = 0; i < B.length; i++) { if (min > max) { break; } long mn = 0; long mx = 0; if (operators.charAt(i) == '-') { mn = Math.max(1, min - B[i]); mx = (max == INF) ? INF : max - B[i]; } else { mx = B[i] - min; mn = Math.max(B[i] - max, 1); } min = mn; max = mx; } if (max < min) { return 0; } if (max == INF) { return -1; } return (int) (max - min + 1); }
public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); int depth = input.nextInt(); int n = (1 << (depth + 1)); int[] as = new int[n]; for (int i = 2; i < n; i++) as[i] = input.nextInt(); int[] paths = new int[n]; int max = 0; ArrayList<Integer>[] under = new ArrayList[n]; for (int i = 0; i < n; i++) under[i] = new ArrayList<Integer>(); for (int i = (1 << (depth)); i < n; i++) { int cur = i; while (cur > 1) { under[cur].add(i); paths[i] += as[cur]; cur /= 2; } max = Math.max(max, paths[i]); } int res = 0; for (int i = 2; i < n; i++) { int cm = 0; for (int x : under[i]) cm = Math.max(cm, paths[x]); int diff = max - cm; res += diff; for (int x : under[i]) paths[x] += diff; } out.println(res); out.close(); }
public Message(String message) { Vector indexes = new Vector(); int pos1 = message.indexOf(NMC_STATUS); if (pos1 != -1) { indexes.addElement(new Index(NMC_STATUS, pos1)); } int pos2 = message.indexOf(NMC_ERRTYPE); if (pos2 != -1) { indexes.addElement(new Index(NMC_ERRTYPE, pos2)); } int pos3 = message.indexOf(NMC_ERRINFO); if (pos3 != -1) { indexes.addElement(new Index(NMC_ERRINFO, pos3)); } int pos4 = message.indexOf(NMC_ERRDETAIL); if (pos4 != -1) { indexes.addElement(new Index(NMC_ERRDETAIL, pos4)); } int pos5 = message.indexOf(NMC_DESCRIPTION); if (pos5 != -1) { indexes.addElement(new Index(NMC_DESCRIPTION, pos5)); } int extraIndex = message.indexOf('\n', Math.max(Math.max(Math.max(pos1, pos2), Math.max(pos3, pos4)), pos5)); if (extraIndex != -1) { NMC_Extra = message.substring(extraIndex + 1, message.length()); /* temp solution until Yu-Jen can think up another header schema */ NMC_Extra = KeyCertUtility.replace(NMC_Extra, "Content-type: text/html", ""); } indexes.addElement(new Index(NMC_EXTRA, extraIndex + 1)); int size = indexes.size(); for (int i = 0; i < size - 1; i++) { Index beginIndex = (Index) (indexes.elementAt(i)); Index endIndex = (Index) (indexes.elementAt(i + 1)); if (beginIndex.getIndexValue().equals(NMC_STATUS)) { String val = message.substring(beginIndex.getPos() + NMC_STATUS.length(), endIndex.getPos()); NMC_Status = Integer.parseInt(val.trim()); } else if (beginIndex.getIndexValue().equals(NMC_DESCRIPTION)) { NMC_Description = message.substring(beginIndex.getPos() + NMC_DESCRIPTION.length(), endIndex.getPos()); } else if (beginIndex.getIndexValue().equals(NMC_ERRTYPE)) { NMC_ErrType = message.substring(beginIndex.getPos() + NMC_ERRTYPE.length(), endIndex.getPos()); } else if (beginIndex.getIndexValue().equals(NMC_ERRINFO)) { NMC_ErrInfo = message.substring(beginIndex.getPos() + NMC_ERRINFO.length(), endIndex.getPos()); } else if (beginIndex.getIndexValue().equals(NMC_ERRDETAIL)) { NMC_ErrDetail = message.substring(beginIndex.getPos() + NMC_ERRDETAIL.length(), endIndex.getPos()); } } }
private Rectangle layoutRects() { int limit = helpers.size(); int visiCount = 0; int maxHeight = 50; int maxWidth = 50; int nextVisibleCol = Integer.MAX_VALUE; for (int i = 0; i < limit; i++) { TDHelper thisHelper = helpers.elementAt(i); if (thisHelper.indentation > nextVisibleCol) { thisHelper.drawRect = null; continue; } if (thisHelper.subsVisible) { nextVisibleCol = Integer.MAX_VALUE; } else { nextVisibleCol = thisHelper.indentation; } thisHelper.layoutRect(visiCount, thisHelper.indentation, auxData); visiCount++; maxWidth = Math.max(maxWidth, thisHelper.drawRect.x + thisHelper.drawRect.width); maxHeight = Math.max(maxHeight, thisHelper.drawRect.y + thisHelper.drawRect.height); } Rectangle rtnVal = new Rectangle(maxWidth + TDHelper.rowPixelBase, maxHeight + TDHelper.colPixelBase); this.setSize(Math.max(500, rtnVal.width), Math.max(500, rtnVal.height)); return rtnVal; }
// 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(); }
public void ensurePositive() { count = Math.max(0, count); size = Math.max(0, size); histoCountsSum = 0; for (int i = 0; i < histoCounts.length; i++) { histoCounts[i] = Math.max(0, histoCounts[i]); histoCountsSum += histoCounts[i]; } }
private void setHoverLocation( org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) { org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds(); org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds(); shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0); shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0); shell.setBounds(shellBounds); }
private int getSumBufferSize(int bytesPerSum, int bufferSize) { int defaultBufferSize = getConf() .getInt( LocalFileSystemConfigKeys.LOCAL_FS_STREAM_BUFFER_SIZE_KEY, LocalFileSystemConfigKeys.LOCAL_FS_STREAM_BUFFER_SIZE_DEFAULT); int proportionalBufferSize = bufferSize / bytesPerSum; return Math.max(bytesPerSum, Math.max(proportionalBufferSize, defaultBufferSize)); }
/** * This returns a blacker color than c. * * @param color * @return a blacker color than c */ public static Color blacker(Color color) { int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); return new Color( Math.max(0, r - (255 - r) / 4), // little changes close to 255 have big effect Math.max(0, g - (255 - g) / 4), Math.max(0, b - (255 - b) / 4)); }
public int getInt(String key, int def, int min) { try { String v = getValue(key); if (v != null) { return Math.max(Integer.parseInt(v), min); } } catch (Exception e) { } return Math.max(def, min); }
/** * Return the size of the area occupied by the contained figures inside the drawing. This method * is called by checkMinimumSize(). */ protected Dimension getDrawingSize() { FigureEnumeration fe = drawing().figures(); Dimension d = new Dimension(0, 0); while (fe.hasNextFigure()) { Rectangle r = fe.nextFigure().displayBox(); d.width = Math.max(d.width, r.x + r.width); d.height = Math.max(d.height, r.y + r.height); } return d; }
public static ArthurImage multiply(ArthurImage one, ArthurImage two) { BufferedImage image = JavaImageMath.clone(one.bf); BufferedImage image2 = JavaImageMath.clone(two.bf); WritableRaster r1 = image.getRaster(); WritableRaster r2 = image2.getRaster(); int newWidth = Math.max(r1.getWidth(), r2.getWidth()); int newHeight = Math.max(r1.getHeight(), r2.getHeight()); BufferedImage collage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); WritableRaster raster = collage.getRaster(); int[] p1 = new int[3]; int[] p2 = new int[3]; int[] pixelArray = new int[3]; for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { p1 = null; p2 = null; if (x < r1.getWidth() && y < r1.getHeight()) { p1 = r1.getPixel(x, y, p1); } if (x < r2.getWidth() && y < r2.getHeight()) { p2 = r2.getPixel(x, y, p2); } for (int i = 0; i < 3; i++) { if (p1 == null && p2 == null) { pixelArray[i] = 0; } else if (p1 == null && p2 != null) { pixelArray[i] = p2[i]; } else if (p1 != null && p2 == null) { pixelArray[i] = p1[i]; } else { pixelArray[i] = (int) ((p1[i] + p2[i]) / 2); } } raster.setPixel(x, y, pixelArray); } } // save image String outputFn = one.filename.substring(0, one.filename.indexOf(".jpg")) + "X" + // filename can't contain the / or *characters; decide later two.filename.substring(0, two.filename.indexOf(".jpg")) + counter + ".jpg"; counter++; return new ArthurImage(collage, outputFn); }
/** * Returns the maximum amount of space the layout can use. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize(Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if (root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } if (root.getMenuBar() != null) { mbd = root.getMenuBar().getMaximumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof HokageRootPaneUI)) { JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane(); if (titlePane != null) { tpd = titlePane.getMaximumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); }
public static Color contrast(Color col) { int max = Math.max(col.getRed(), Math.max(col.getGreen(), col.getBlue())); if (max > 128) { return (new Color(col.getRed() / 2, col.getGreen() / 2, col.getBlue() / 2, col.getAlpha())); } else if (max == 0) { return (Color.WHITE); } else { int f = 128 / max; return (new Color(col.getRed() * f, col.getGreen() * f, col.getBlue() * f, col.getAlpha())); } }
static void sweep(ArrayList<Integer> indexes) { PriorityQueue<Event> pq = new PriorityQueue<Event>(); for (int i = 0; i < indexes.size(); i++) { pq.offer(new Event(lo[val[indexes.get(i)]] + 1, 1, indexes.get(i))); pq.offer(new Event(hi[val[indexes.get(i)]], -1, indexes.get(i))); } TreeSet<Integer> active = new TreeSet<Integer>(); while (!pq.isEmpty()) { Event curr = pq.poll(); if (curr.type == 1) active.add(curr.index); else if (curr.type == -1) { active.remove(curr.index); Integer lower = active.lower(curr.index); if (lower != null && lower > lo[val[curr.index]]) { Interval add = new Interval(lower, curr.index); Interval prev = intervals.floor(add); Interval next = intervals.ceiling(add); boolean intersectPrev = true; boolean intersectNext = true; if (prev != null) { if (Math.max(add.l, prev.l) < Math.min(add.r, prev.r)) { if (add.r - add.l <= prev.r - prev.l) { intervals.remove(prev); intersectPrev = false; } } else { intersectPrev = false; } } else { intersectPrev = false; } if (next != null) { if (Math.max(add.l, next.l) < Math.min(add.r, next.r)) { if (add.r - add.l <= next.r - next.l) { intervals.remove(next); intersectNext = false; } } else { intersectNext = false; } } else { intersectNext = false; } if (!intersectPrev && !intersectNext) intervals.add(add); } } } }
static int solve(int pos1, int pos2, int size) { if (pos1 <= 0 || pos2 <= 0 || size <= 0) { return 0; } if (dp[pos1][pos2][size] != -1) return dp[pos1][pos2][size]; int aa = 0, bb, c; if (s.charAt(pos1 - 1) == s1.charAt(pos2 - 1)) { aa = solve(pos1 - 1, pos2 - 1, size - 1) + (int) s.charAt(pos1 - 1); } bb = solve(pos1 - 1, pos2, size); c = solve(pos1, pos2 - 1, size); return dp[pos1][pos2][size] = Math.max(aa, Math.max(bb, c)); }
private WVirtualImage.Rect neighbourhood(long x, long y, int marginX, int marginY) { long x1 = x - marginX; if (this.imageWidth_ != Infinite) { x1 = Math.max((long) 0, x1); } long y1 = Math.max((long) 0, y - marginY); long x2 = x + this.viewPortWidth_ + marginX; if (this.imageWidth_ != Infinite) { x2 = Math.min(this.imageWidth_, x2); } long y2 = Math.min(this.imageHeight_, y + this.viewPortHeight_ + marginY); return new WVirtualImage.Rect(x1, y1, x2, y2); }
public static int max_sum(int[] arr) { if (arr.length == 1) return arr[0]; else if (arr.length == 2) return Math.max(arr[0], arr[1]); else { int[] cache = new int[arr.length]; cache[0] = arr[0]; cache[1] = arr[1] > arr[0] ? arr[1] : arr[0]; for (int i = 2; i < cache.length; i++) { cache[i] = Math.max(cache[i - 1], arr[i] + cache[i - 2]); } return cache[cache.length - 1]; } }
private void internalScrollTo(long newX, long newY, boolean moveViewPort) { if (this.imageWidth_ != Infinite) { newX = Math.min(this.imageWidth_ - this.viewPortWidth_, Math.max((long) 0, newX)); } if (this.imageHeight_ != Infinite) { newY = Math.min(this.imageHeight_ - this.viewPortHeight_, Math.max((long) 0, newY)); } if (moveViewPort) { this.contents_.setOffsets(new WLength((double) -newX), EnumSet.of(Side.Left)); this.contents_.setOffsets(new WLength((double) -newY), EnumSet.of(Side.Top)); } this.generateGridItems(newX, newY); this.viewPortChanged_.trigger(this.currentX_, this.currentY_); }
private ArrayList sortScans(String name, List<Level2Record> scans, int siz) { // now group by elevation_num Map<Short, List<Level2Record>> groupHash = new HashMap<Short, List<Level2Record>>(siz); for (Level2Record record : scans) { List<Level2Record> group = groupHash.get(record.elevation_num); if (null == group) { group = new ArrayList<Level2Record>(); groupHash.put(record.elevation_num, group); } group.add(record); } // sort the groups by elevation_num ArrayList groups = new ArrayList(groupHash.values()); Collections.sort(groups, new GroupComparator()); // use the maximum radials for (int i = 0; i < groups.size(); i++) { ArrayList group = (ArrayList) groups.get(i); Level2Record r = (Level2Record) group.get(0); if (runCheck) testScan(name, group); if (r.getGateCount(REFLECTIVITY_HIGH) > 500 || r.getGateCount(VELOCITY_HIGH) > 1000) { max_radials_hr = Math.max(max_radials_hr, group.size()); min_radials_hr = Math.min(min_radials_hr, group.size()); } else { max_radials = Math.max(max_radials, group.size()); min_radials = Math.min(min_radials, group.size()); } } if (debugRadials) { System.out.println(name + " min_radials= " + min_radials + " max_radials= " + max_radials); for (int i = 0; i < groups.size(); i++) { ArrayList group = (ArrayList) groups.get(i); Level2Record lastr = (Level2Record) group.get(0); for (int j = 1; j < group.size(); j++) { Level2Record r = (Level2Record) group.get(j); if (r.data_msecs < lastr.data_msecs) System.out.println(" out of order " + j); lastr = r; } } } testVariable(name, groups); if (debugScans) System.out.println("-----------------------------"); return groups; }
double calculate_rho() { int nr_free1 = 0,nr_free2 = 0; double ub1 = INF, ub2 = INF; double lb1 = -INF, lb2 = -INF; double sum_free1 = 0, sum_free2 = 0; for(int i=0;i<active_size;i++) { if(y[i]==+1) { if(is_lower_bound(i)) ub1 = Math.min(ub1,G[i]); else if(is_upper_bound(i)) lb1 = Math.max(lb1,G[i]); else { ++nr_free1; sum_free1 += G[i]; } } else { if(is_lower_bound(i)) ub2 = Math.min(ub2,G[i]); else if(is_upper_bound(i)) lb2 = Math.max(lb2,G[i]); else { ++nr_free2; sum_free2 += G[i]; } } } double r1,r2; if(nr_free1 > 0) r1 = sum_free1/nr_free1; else r1 = (ub1+lb1)/2; if(nr_free2 > 0) r2 = sum_free2/nr_free2; else r2 = (ub2+lb2)/2; si.r = (r1+r2)/2; return (r1-r2)/2; }
public static long possibilities(int streak, int minLastDigit, int maxStartingDigit) { long ret = pow2(streak - 1); // This part is wrong! if (minLastDigit >= 2) { ret -= pow2(minLastDigit - 2); if (ret < 0) ret += mod; } for (int i = 2; i <= maxStartingDigit; i++) { ret = (ret * 2) % mod; ret = (ret + possibilities(Math.max(streak - i + 1, 1), Math.max(minLastDigit - i + 1, 1), 1)) % mod; } return ret; }