예제 #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");
    }
  }
예제 #2
0
  protected TextLayout getTextLayout() {
    if (textLayout == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (get(FONT_UNDERLINE)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
      }
      textLayout = new TextLayout(text, textAttributes, frc);
    }
    return textLayout;
  }
예제 #3
0
  private Shape getTextShape() {
    if (cachedTextShape == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (FONT_UNDERLINE.get(this)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
      }
      TextLayout textLayout = new TextLayout(text, textAttributes, frc);

      AffineTransform tx = new AffineTransform();
      tx.translate(coordinates[0].x, coordinates[0].y);
      switch (TEXT_ANCHOR.get(this)) {
        case END:
          tx.translate(-textLayout.getAdvance(), 0);
          break;
        case MIDDLE:
          tx.translate(-textLayout.getAdvance() / 2d, 0);
          break;
        case START:
          break;
      }
      tx.rotate(rotates[0]);

      /*
      if (TRANSFORM.get(this) != null) {
          tx.preConcatenate(TRANSFORM.get(this));
      }*/

      cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx));
      cachedTextShape = textLayout.getOutline(tx);
    }
    return cachedTextShape;
  }
  /** 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;
  }
예제 #5
0
  public static Map<String, String> getStyles(String str) throws IOException {
    HashMap<String, String> styles = new HashMap<String, String>();
    if (str == null) return styles;

    StreamTokenizer tt = new StreamTokenizer(new StringReader(str));
    tt.resetSyntax();
    tt.wordChars('!', '9');
    tt.wordChars('<', '~');
    tt.wordChars(128 + 32, 255);
    tt.whitespaceChars(0, ' ');

    while (tt.nextToken() != StreamTokenizer.TT_EOF) {
      if (tt.ttype != ';') {
        String key, value;
        if (tt.ttype != StreamTokenizer.TT_WORD) {
          throw new IOException(
              "Key token expected in " + str + " " + Integer.toHexString(tt.ttype));
        }
        key = tt.sval;
        if (tt.nextToken() != ':') {
          throw new IOException("Colon expected after " + key + " in " + str);
        }
        if (tt.nextToken() != StreamTokenizer.TT_WORD) {
          throw new IOException(
              "Value token expected after " + key + " in " + str + " " + tt.ttype);
        }
        value = tt.sval;
        while (tt.nextToken() == StreamTokenizer.TT_WORD) {
          value += ' ' + tt.sval;
        }
        tt.pushBack();
        styles.put(key, value);
      }
    }

    return styles;
  }
  /** 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()));
          }
        }
      }
    }
  }