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);
      }
    }
 public XYSeries getXYSeries(String rowname, long factor) {
   XYSeries mydataset = new XYSeries(rowname);
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     mydataset.add(point / factor, value);
   }
   return mydataset;
 }
Пример #3
0
 // static initialization
 static {
   sbmlUnitNames = new HashMap<Integer, String>();
   sbmlUnitKinds = new HashMap<String, Integer>();
   for (int i = 0; i < SBML_UNIT_NAMES.length; i++) {
     String name = SBML_UNIT_NAMES[i];
     Integer code = new Integer(SBML_UNIT_KINDS[i]);
     sbmlUnitNames.put(code, name);
     sbmlUnitKinds.put(name, code);
   }
 }
  @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 YIntervalSeries getYIntervalSeries(String rowname, long factor) {
   YIntervalSeries mydataset = new YIntervalSeries(rowname);
   double sdcount = 0;
   double total = 0;
   Vector<Double> totalvalues = new Vector<Double>();
   double avgtotal = 0;
   double minus = 0;
   double plus = 0;
   double zero = 0;
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     Vector<Double> listofvalues = values.get(key);
     double sumofdiff = 0.0;
     for (Double onevalue : listofvalues) {
       sumofdiff += Math.pow(onevalue - value, 2);
       sdcount++;
       total += Math.pow(onevalue, 2);
       avgtotal += onevalue;
       totalvalues.add(onevalue);
       if (onevalue == 1) {
         plus++;
       }
       ;
       if (onevalue == -1) {
         minus++;
       }
       ;
       if (onevalue == 0) {
         zero++;
       }
       ;
     }
     double sd = Math.sqrt(sumofdiff / count.get(key));
     // mydataset.add(point/factor, value,value+sd,value-sd);
     // mydataset.add(point/factor, value,value,value);
     mydataset.add(
         point / factor,
         value,
         value + 1.96 * (sd / Math.sqrt(count.get(key))),
         value - 1.96 * (sd / Math.sqrt(count.get(key))));
   }
   double sdtotal = 0;
   double avgsd = total / sdcount;
   double test = 0;
   for (Double onevalue : totalvalues) {
     sdtotal += Math.pow(Math.pow(onevalue, 2) - (total / sdcount), 2);
     test += onevalue;
   }
   // System.out.println(rowname+" mean square: "+avgsd+"
   // +/-95%:"+1.96*Math.sqrt(sdtotal/sdcount)/Math.sqrt(sdcount));
   // System.out.println("total -1:"+minus+" total +1:"+plus+" zero: "+zero
   // +" total:"+sdcount);
   return mydataset;
 }
Пример #6
0
  public FunctionalTest() throws IOException {
    Vector v = new Vector();
    for (Enumeration e = v.elements(); e.hasMoreElements(); ) {}
    IOException e = new IOException();

    // this is to test excluding literals
    String buz = "text/plain";

    // this is to test array handling
    ArrayList[] foo = new ArrayList[0];
    ArrayList bar = new ArrayList();
    bar.add(HashSet.class);
    bar.add(Integer.class);
    File[] files = (File[]) bar.toArray(new File[0]);

    // this is to test imports of inner classes
    HashMap biv = new HashMap();
    Set set = biv.entrySet();
    Iterator iter = set.iterator();
    bar.add((Entry) iter.next());

    // this is to test inclusion of classes from java.lang.reflect
    Modifier m = new Modifier();

    // This next one can't be picked up by importscrubber because the compiler inlines it
    // System.out.println("A JOptionPane thingy " + JOptionPane.CANCEL_OPTION);
    // bummer!

    // this is to test importing a class and only calling a static method on it
    // Buz.doSomething();

    // this is to test NOT importing classes which are fully qualified in the class body
    // java.sql.Date sqlDate = new java.sql.Date(20);
    // Date javaDate = new Date();

    throw new IllegalArgumentException();
  }
  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();
    }
  }
Пример #8
0
 public static int stringToKind(String name) {
   Integer kind = sbmlUnitKinds.get(name);
   return (kind == null) ? libsbmlConstants.UNIT_KIND_INVALID : kind.intValue();
 }
Пример #9
0
 // SBML kind/String lookups
 public static String kindToString(int kind) {
   return sbmlUnitNames.get(new Integer(kind));
 }