Ejemplo n.º 1
0
  public Main() {
    try {
      BufferedReader in;
      in = new BufferedReader(new InputStreamReader(System.in)); // Used for CCC
      int numLights = Integer.parseInt(in.readLine());
      int[] states = new int[numLights];
      for (int i = 0; i < numLights; i++) {
        states[i] = Integer.parseInt(in.readLine());
      }
      ArrayDeque<Scenario> Q = new ArrayDeque<Scenario>();
      HashMap<String, Integer> dp = new HashMap<String, Integer>();

      int moves = 0;
      Q.addLast(new Scenario(states));
      while (!Q.isEmpty()) {
        int size = Q.size();
        for (int q = 0; q < size; q++) {
          Scenario temp = Q.removeFirst();
          if (isEmpty(temp.states)) {
            System.out.println(moves);
            return;
          } else {
            for (int i = 0; i < temp.states.length; i++) {
              if (temp.states[i] == 0) {
                int[] newArr = Arrays.copyOf(temp.states, temp.states.length);
                newArr[i] = 1;
                newArr = fixArray(newArr);
                String arr = "";
                for (int p = 0; p < newArr.length; p++) arr += newArr[p];
                if (dp.get(arr) == null) {
                  dp.put(arr, moves);
                  Q.addLast(new Scenario(newArr));
                } else {
                  int val = dp.get(arr);
                  if (val != 0 && moves < val) {
                    dp.put(arr, moves);
                    Q.addLast(new Scenario(newArr));
                  }
                }

                // outputArr(newArr);
              }
            }
          }
        }
        moves++;
      }

    } catch (IOException e) {
      System.out.println("IO: General");
    }
  }
  /** Read a glyph, given an index */
  public GlyphData readGlyph(int index) {
    String sid = getSID(index);

    if (charset.containsKey(sid)) {
      return (GlyphData) charset.get(sid);
    }

    Range r = getIndexEntry(charstringbase, index);

    FlPoint pt = new FlPoint();
    GlyphData gd = new GlyphData();

    parseGlyph(r, gd, pt);
    gd.setName(sid);

    charset.put(sid, gd);
    return gd;
  }
Ejemplo n.º 3
0
  void buildArrow(HashMap<String, String> item) {
    String s;

    s = item.get("fromx").trim();
    fromX = Integer.parseInt(s);
    s = item.get("fromy").trim();
    fromY = Integer.parseInt(s);
    s = item.get("tox").trim();
    toX = Integer.parseInt(s);
    s = item.get("toy").trim();
    toY = Integer.parseInt(s);
    upStreamPort = item.get("upstreamport");
    downStreamPort = item.get("downstreamport");
    s = item.get("dropoldest");
    if (s != null) dropOldest = true;
    s = item.get("fromid").trim();
    fromId = Integer.parseInt(s);

    s = item.get("toid").trim();
    toId = Integer.parseInt(s);
    s = item.get("id");
    if (s == null) id = 0;
    else id = Integer.parseInt(s.trim());
    if (id == 0) id = diag.maxArrowNo + 1;

    diag.maxArrowNo = Math.max(id, diag.maxArrowNo);

    endsAtBlock = true;
    endsAtLine = false;
    s = item.get("fromside");
    if (s != null) {
      s = s.trim();
      if (s.equals("L")) fromSide = Side.LEFT;
      else if (s.equals("R")) fromSide = Side.RIGHT;
      else if (s.equals("T")) fromSide = Side.TOP;
      else if (s.equals("B")) fromSide = Side.BOTTOM;
    }
    s = item.get("toside");
    if (s != null) {
      s = s.trim();
      if (s.equals("L")) toSide = Side.LEFT;
      else if (s.equals("R")) toSide = Side.RIGHT;
      else if (s.equals("T")) toSide = Side.TOP;
      else if (s.equals("B")) toSide = Side.BOTTOM;
    }
  }
  /** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }
Ejemplo n.º 5
0
  public void dataUpdate() {
    // 日付関係はUGUIUpdateManager経由で取得するように変更.
    int date = UGUIUpdateManager.getDate();
    int boardNo = UGUIUpdateManager.getBoard();
    int step = UGUIUpdateManager.getStep();
    int now = UGUIUpdateManager.getMarketStatus();

    if (now != fCurrentStatus) {
      fIsUpdated = true;
    }

    if (step <= fCurrentStep) {
      // Exchange X-Y がセットされている場合の処理.フラグ処理はあまりきれいではないが
      // X-Y の入れ換え自体が???なので勘弁してもらおう.
      if (fIsUpdated == false) {
        return;
      } else {
        fIsUpdated = false;
      }
    }

    if (boardNo == 1) {
      fDay.setText(String.valueOf(date - 1));
      fBoard.setText(String.valueOf(fParam.getBoardPerDay()));
    } else {
      fDay.setText(String.valueOf(date));
      if (now == fCurrentStatus) {
        fBoard.setText(String.valueOf(boardNo - 1));
      } else {
        fBoard.setText(String.valueOf(boardNo));
      }
    }
    fCurrentStep = step;
    fCurrentStatus = now;

    UCBoardDataCore cBoardData = (UCBoardDataCore) fCProtocol.getCommand(UCBoardDataCore.CMD_NAME);
    UCommandStatus status = cBoardData.doIt();
    ArrayList array;
    HashMap boardDataInfo;
    long maxPrice, minPrice, totalBuyVolume;
    Vector printData = new Vector();
    if (status.getStatus()) {
      array = cBoardData.getBoardDataArray();
      boardDataInfo = cBoardData.getBoardDataInfo();
      maxPrice = ((Long) boardDataInfo.get(UCBoardDataCore.LONG_MAX_PRICE)).longValue();
      minPrice = ((Long) boardDataInfo.get(UCBoardDataCore.LONG_MIN_PRICE)).longValue();
      totalBuyVolume =
          ((Long) boardDataInfo.get(UCBoardDataCore.LONG_TOTAL_BUY_VOLUME)).longValue();
      if (fIsExchangeXY == false) {
        fBoardGraph.setFixedMaxX(maxPrice);
        fBoardGraph.setFixedMinX(minPrice);
        fBoardGraph.setFixedMaxY(totalBuyVolume);
        fBoardGraph.setFixedMinY(0);
      } else {
        fBoardGraph.setFixedMaxX(totalBuyVolume);
        fBoardGraph.setFixedMinX(0);
        fBoardGraph.setFixedMaxY(maxPrice);
        fBoardGraph.setFixedMinY(minPrice);
      }
    } else {
      return;
    }
    long contractPrice =
        ((Long) boardDataInfo.get(UCBoardDataCore.LONG_CONTRACT_PRICE)).longValue();
    long contractVolume =
        ((Long) boardDataInfo.get(UCBoardDataCore.LONG_CONTRACT_VOLUME)).longValue();
    fContractPriceTextField.setText(String.valueOf(contractPrice));
    fContractVolumeTextField.setText(String.valueOf(contractVolume));
    ArrayList tmpSellData = new ArrayList();
    ArrayList tmpBuyData = new ArrayList();
    ArrayList tmpContractData = new ArrayList();
    if (fIsExchangeXY == false) {
      tmpContractData.add(new Point2D.Double(minPrice, contractVolume));
      tmpContractData.add(new Point2D.Double(contractPrice, contractVolume));
      tmpContractData.add(new Point2D.Double(contractPrice, 0));
      fBoardGraph.setXLableName("price");
      fBoardGraph.setYLableName("volume");
    } else {
      tmpContractData.add(new Point2D.Double(contractVolume, minPrice));
      tmpContractData.add(new Point2D.Double(contractVolume, contractPrice));
      tmpContractData.add(new Point2D.Double(0, contractPrice));
      fBoardGraph.setXLableName("volume");
      fBoardGraph.setYLableName("price");
    }
    Iterator iter = array.iterator();
    double tmpPrice, tmpVolume, currentSellVolume = 0, currentBuyVolume = totalBuyVolume;
    while (iter.hasNext()) {
      HashMap os = (HashMap) iter.next();
      String s = (String) os.get(UCBoardDataCore.STRING_SELL_BUY);
      if (s.equals("sell")) {
        tmpPrice = ((Long) os.get(UCBoardDataCore.LONG_PRICE)).doubleValue();
        tmpVolume = ((Long) os.get(UCBoardDataCore.LONG_VOLUME)).doubleValue();
        if (fIsExchangeXY == false) {
          tmpSellData.add(new Point2D.Double(tmpPrice, currentSellVolume));
          tmpSellData.add(new Point2D.Double(tmpPrice, currentSellVolume + tmpVolume));
        } else {
          tmpSellData.add(new Point2D.Double(currentSellVolume, tmpPrice));
          tmpSellData.add(new Point2D.Double(currentSellVolume + tmpVolume, tmpPrice));
        }
        currentSellVolume += tmpVolume;
      } else if (s.equals("buy")) {
        tmpPrice = ((Long) os.get(UCBoardDataCore.LONG_PRICE)).doubleValue();
        tmpVolume = ((Long) os.get(UCBoardDataCore.LONG_VOLUME)).doubleValue();
        if (fIsExchangeXY == false) {
          tmpBuyData.add(new Point2D.Double(tmpPrice, currentBuyVolume));
          tmpBuyData.add(new Point2D.Double(tmpPrice, currentBuyVolume - tmpVolume));
        } else {
          tmpBuyData.add(new Point2D.Double(currentBuyVolume, tmpPrice));
          tmpBuyData.add(new Point2D.Double(currentBuyVolume - tmpVolume, tmpPrice));
        }
        currentBuyVolume -= tmpVolume;
      }
    }
    ((UGraphData) fBoardGraph.getGraph().get(0)).setData(tmpSellData);
    ((UGraphData) fBoardGraph.getGraph().get(1)).setData(tmpBuyData);
  }