public void addValue(long x, double y) { // calculate the bar in which this value should go int bar = (int) (x / barsize); double Y = y; if (ysum.containsKey(bar)) { double newyvalue = Y + ysum.get(bar); long newxvalue = x + xsum.get(bar); Integer newcount = count.get(bar) + 1; ysum.put(bar, newyvalue); xsum.put(bar, newxvalue); count.put(bar, newcount); Vector<Double> barvalues = values.get(bar); barvalues.add(Y); values.put(bar, barvalues); } else { ysum.put(bar, Y); xsum.put(bar, x); count.put(bar, 1); Vector<Double> barvalues = new Vector<Double>(); barvalues.add(Y); values.put(bar, barvalues); } }
@SuppressWarnings("unchecked") public int getMinimumMoves(String[] board) { PriorityQueue<Long> pq = new PriorityQueue<Long>(); HashMap<Long, Integer> map = new HashMap<Long, Integer>(); ArrayList<Integer> pieces = new ArrayList<Integer>(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (board[i].charAt(j) == '*') { pieces.add((i << 3) | j); } } } N = pieces.size(); pq.add(pack(pieces)); while (pq.size() > 0) { long a = pq.poll(); long k = a & 0xFFFFFFFFL; int c = (int) (a >>> 32); if (map.containsKey(k)) continue; map.put(k, c); ArrayList<Integer> unpack = unpack(k); if (connected(unpack)) return c; for (int i = 0; i < N; i++) { int piece = unpack.get(i); int x = piece >>> 3; int y = piece & 0x7; for (int j = 0; j < dir.length; j++) { ArrayList<Integer> copy = (ArrayList<Integer>) unpack.clone(); copy.remove(i); if (x + dir[j][0] < 0 || x + dir[j][0] >= 5 || y + dir[j][1] < 0 || y + dir[j][1] >= 5) continue; int newp = ((x + dir[j][0]) << 3) | (y + dir[j][1]); if (copy.contains(newp)) continue; copy.add(newp); long test = pack(copy); if (map.get(test) == null || map.get(test) > c + 1) { pq.add((((long) c + 1) << 32) | test); } } } } return -1; }
public void solve() { // Scanner sc = new Scanner(System.in); // int n = Integer.parseInt(sc.nextLine()); // n = 10000; pr("\n".getBytes()); int n = ni(); // int xx=100000; while (n != 0) { String s = ns1(); // int size = (int)(Math.random()*10000); // char [] axx = new char[size]; // for (int i = 0; i < axx.length; i++) { // char ccc = (char)((Math.random()*('z'-'a'))+'a'); //// pr(ccc); // axx[i]=ccc; // } // String s =new String(axx); // for (int i = 0; i < 1000000; i++) { // s+='x'; // } // int[] xa = new int[1000000000]; // pr(s); int a = 0; HashMap<Character, Integer> set = new HashMap<Character, Integer>(); // int [] alf= new int[128]; int r = 0; for (int i = 0; i < s.length(); i++) { // pr(set); // char that = s.charAt(a); char thix = s.charAt(i); if (set.size() < n) { Integer ax = set.get(thix); if (ax == null) { set.put(thix, 1); } else set.put(thix, ax + 1); } else if (set.size() == n) { if (!set.containsKey(thix)) { while (set.size() == n && a < s.length()) { char that = s.charAt(a); if (set.containsKey(that) && set.get(that) > 1) set.put(that, set.get(that) - 1); else set.remove(that); a++; } set.put(thix, 1); } else set.put(thix, set.get(thix) + 1); } int newr = i - a + 1; // pr(newr, set,a,i,s.substring(a,i)); if (newr > r) { // pr() // pr(set,a,i,s.substring(a,i)); r = newr; } // r=max(r,); } out.println(r); // n = (int)(Math.random()*128); n = ni(); } }