示例#1
1
文件: E4.java 项目: hiroshi-cl/wakaba
 boolean go(double ntime, Box box) {
   debug("go");
   g(ntime);
   for (int i = 0; i < bs.size() - 1; i++)
     if (bs.get(i) == box) {
       Box nb = box.h1 <= box.h2 ? bs.get(i - 1) : bs.get(i + 1);
       if (eq(nb.h, box.h)) {
         Box nbox = box.combine(nb);
         bs.remove(box);
         bs.add(i, nbox);
         bs.remove(nb);
       } else {
         nb.f += box.f;
         box.f = 0;
       }
       return true;
     }
   return false;
 }
  public ArrayList<ArrayList<float[]>> getGestureTracesByID(String id) {
    /*
     *  this convenience method returns
     *  gesture traces as arrays
     *
     */

    ArrayList<Gesture> gestures = this.getGesturesByID(id);

    if (gestures != null) {
      int g_count = gestures.size();
      ArrayList<ArrayList<float[]>> out =
          new ArrayList<ArrayList<float[]>>(g_count); // new float[g_count][][];
      ArrayList<float[][]> traces = new ArrayList<float[][]>(10);

      Iterator<Gesture> it = gestures.iterator();
      // collect the gesture traces (hopefully no copying!)
      int g_maxLength = 0; // max length of the gestures --> to fill the array (?)
      int g_idx = 0;
      while (it.hasNext()) {
        Gesture g = it.next();
        out.add(g.gestureTrace);
      }

      return out;
      // no fill up the array
    } else {
      Log.i("getGestureTracesByID", "No Gestures for id " + id);
      return null;
    }
  }
示例#3
0
文件: A1.java 项目: paohui817/arena
 public int totalNQueens(int n) {
   StringBuilder[] board = new StringBuilder[n];
   for (int i = 0; i < n; i++) {
     board[i] = new StringBuilder();
     for (int j = 0; j < n; j++) {
       board[i].append('.');
     }
   }
   for (int i = 0; i < n / 2; i++) {
     board[0].setCharAt(i, 'Q');
     dfs(n, 1, board);
     board[0].setCharAt(i, '.');
   }
   ArrayList<String[]> aux = new ArrayList<String[]>();
   for (String[] k : res) {
     String[] tmp = new String[n];
     for (int i = 0; i < n; i++) {
       StringBuilder sb = new StringBuilder(k[i]).reverse();
       tmp[i] = sb.toString();
     }
     aux.add(tmp);
   }
   res.addAll(aux);
   if (n % 2 != 0) {
     board[0].setCharAt(n / 2, 'Q');
     dfs(n, 1, board);
     board[0].setCharAt(n / 2, '.');
   }
   return res.size();
 }
示例#4
0
文件: A1.java 项目: paohui817/arena
 public void solve(InputReader in, OutputWriter out) {
   int n = in.nextInt();
   ArrayList<String> a = new ArrayList<>();
   for (int i = 0; i < n; i++) {
     a.add(in.next());
   }
   TreeNode tree = new TreeNode(a);
   int res = new A1().maxPathSum(tree);
   out.println(res);
 }
示例#5
0
文件: A1.java 项目: paohui817/arena
 void constructBoard(StringBuilder[] board) {
   String[] tmp = new String[board.length];
   for (int i = 0; i < board.length; i++) {
     tmp[i] = board[i].toString();
   }
   res.add(tmp);
 }
示例#6
0
文件: E4.java 项目: hiroshi-cl/wakaba
 E nextEvent() {
   Box res = bs.get(0);
   double min = res.flowtime();
   for (Box b : bs)
     if (b.flowtime() < min) {
       min = b.flowtime();
       res = b;
     }
   return new F(res, time + min);
 }
  public void addGesture(String id, Gesture g, boolean addtoDB) {
    // verify if the gesture ID exits
    if (myGestureMap.containsKey(id)) {
      myGestureMap.get(id).add(g);
    } else {
      ArrayList<Gesture> gl = new ArrayList<Gesture>(10);
      gl.add(g);
      myGestureMap.put(id, gl);
    }

    if (DEBUG) {
      Log.i("addGesture", "attempting to insert to database");
    }

    myDBAdapter.insertGestureToDB(g);

    if (DEBUG) {
      this.printInfo("addGesture");
    }
  }
示例#8
0
文件: A1.java 项目: paohui817/arena
 public ArrayList<Integer> morrisTraversal() {
   ArrayList<Integer> res = new ArrayList<>();
   TreeNode current = this;
   while (current != null) {
     if (current.left == null) {
       res.add(current.val);
       current = current.right;
     } else {
       TreeNode pre = current.left;
       while (pre.right != null && pre.right != current) {
         pre = pre.right;
       }
       if (pre.right == null) {
         pre.right = current;
         current = current.left;
       } else {
         pre.right = null;
         res.add(current.val);
         current = current.right;
       }
     }
   }
   return res;
 }
示例#9
0
文件: A1.java 项目: paohui817/arena
 public static ArrayList<String> serializeTree(TreeNode tree) {
   ArrayList<String> res = new ArrayList<>();
   LinkedList<TreeNode> queue = new LinkedList<>();
   queue.addLast(tree);
   while (!queue.isEmpty()) {
     TreeNode node = queue.removeFirst();
     if (node == null) {
       res.add(NULL);
     } else {
       res.add(String.valueOf(node.val));
       queue.add(node.left);
       queue.add(node.right);
     }
   }
   while (res.size() > 1 && res.get(res.size() - 1).equals(NULL)) {
     res.remove(res.size() - 1);
   }
   return res;
 }