コード例 #1
0
  public void updateFile() {
    // writes highscore, coins and updates eveything else
    try {
      outFile = new PrintWriter(new BufferedWriter(new FileWriter("stats.txt")));
      outFile.println("" + (money + coins));
      outFile.println("" + powerUps.size());
      for (int i = 0; i < powerUps.size(); i++) {
        outFile.println("" + powerUps.get(i)); // writes the highscore in the file
      }
      outFile.println("" + chars.size());
      for (int i = 0; i < chars.size(); i++) {
        outFile.println("" + chars.get(i));
      }
      if (Integer.parseInt(stats.get(stats.size() - 3)) < score) {
        outFile.println(score);
      } else {
        outFile.println(stats.get(stats.size() - 3));
      }
      if (Integer.parseInt(stats.get(stats.size() - 2)) < score) {
        outFile.println(height);
      } else {
        outFile.println(stats.get(stats.size() - 2));
      }
      outFile.println(Integer.parseInt(stats.get(stats.size() - 1)) + height);

      outFile.close();
    } catch (IOException ex) {
      System.out.println("yooo stop noobing out");
    }
  }
コード例 #2
0
ファイル: AOJ0081.java プロジェクト: t8m8/AOJ
  public static void main(String[] args) {
    long start = System.currentTimeMillis();

    while (in.hasNext()) solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    in.close();
    out.close();
  }
コード例 #3
0
ファイル: AOJ0034.java プロジェクト: t8m8/AOJ
  public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    br.close();
    out.close();
  }
コード例 #4
0
ファイル: AOJ2739.java プロジェクト: t8m8/AOJ
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.nanoTime();

    solve();
    out.flush();

    long end = System.nanoTime();
    dump((end - start) / 1000000 + " ms");
    in.close();
    out.close();
  }
コード例 #5
0
ファイル: B.java プロジェクト: t8m8/AtCoder
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    dump((end - start) + "ms");
    in.close();
    out.close();
  }
コード例 #6
0
ファイル: AOJ0034.java プロジェクト: t8m8/AOJ
  static void solve() throws IOException {
    String str;
    while ((str = br.readLine()) != null) {
      String[] s = str.split(",");
      int[] a = new int[10];
      int sum = 0;
      for (int i = 0; i < 10; i++) {
        a[i] = Integer.parseInt(s[i]);
        sum += a[i];
      }

      int v1 = Integer.parseInt(s[10]);
      int v2 = Integer.parseInt(s[11]);

      double r = (double) sum * v1 / (v1 + v2);

      sum = 0;
      for (int i = 0; i < 10; i++) {
        sum += a[i];
        if (r <= sum) {
          out.println((i + 1));
          break;
        }
      }
    }
  }
コード例 #7
0
ファイル: CF615A.java プロジェクト: t8m8/Codeforces
  static void solve() {
    int n = in.nextInt();
    int m = in.nextInt();
    boolean[] p = new boolean[m];
    for (int i = 0; i < n; i++) {
      int x = in.nextInt();
      for (int j = 0; j < x; j++) {
        p[in.nextInt() - 1] = true;
      }
    }

    for (int i = 0; i < m; i++) {
      if (!p[i]) {
        out.println("NO");
        return;
      }
    }

    out.println("YES");
  }
コード例 #8
0
ファイル: AOJ0081.java プロジェクト: t8m8/AOJ
 static void solve() {
   String[] s = in.next().split(",");
   Point p =
       reflect(
           new Line(
               Double.parseDouble(s[0]),
               Double.parseDouble(s[1]),
               Double.parseDouble(s[2]),
               Double.parseDouble(s[3])),
           new Point(Double.parseDouble(s[4]), Double.parseDouble(s[5])));
   out.println(p.getX() + " " + p.getY());
 }
コード例 #9
0
 /**
  * Writes the figures to the specified output stream.
  * This method applies the specified drawingTransform to the drawing, and draws
  * it on an image of the specified getChildCount.
  * 
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures,
         AffineTransform drawingTransform, Dimension imageSize) throws IOException {
     
     this.drawingTransform = (drawingTransform == null) ? new AffineTransform() : drawingTransform;
     this.bounds = (imageSize == null) ? 
         new Rectangle(0,0,Integer.MAX_VALUE,Integer.MAX_VALUE) :
         new Rectangle(0, 0, imageSize.width, imageSize.height);
     
     XMLElement document = new XMLElement("map");
     
     // Note: Image map elements need to be written from front to back
     for (Figure f: new ReversedList<Figure>(figures)) {
         writeElement(document, f);
     }
     
     // Strip AREA elements with "nohref" attributes from the end of the
     // map
     if (! isIncludeNohref) {
         for (int i=document.getChildrenCount() - 1; i >= 0; i--) {
             XMLElement child = (XMLElement) document.getChildAtIndex(i);
             if (child.hasAttribute("nohref")) {
                 document.removeChildAtIndex(i);
             }
         }
     }
     
     
     // Write XML content
     PrintWriter writer = new PrintWriter(
             new OutputStreamWriter(out, "UTF-8")
             );
     //new XMLWriter(writer).write(document);
     for (Object o : document.getChildren()) {
         XMLElement child = (XMLElement) o;
         new XMLWriter(writer).write(child);
     }
     
     // Flush writer
     writer.flush();
 }
コード例 #10
0
ファイル: LJ3MDApp.java プロジェクト: eskilj/mvp
  //    int frame = 0;
  public void paint(Graphics g) {
    // System.out.println("frame: " + (frame++));
    lStatus.setText(
        "t = "
            + df.format(md.dt * md.step)
            + ", "
            + "N = "
            + md.N
            + ", "
            + "E/N = "
            + df.format(md.E / md.N)
            + ", "
            + "U/N = "
            + df.format(md.U / md.N)
            + ", "
            + "K/N = "
            + df.format(md.K / md.N)
            + ", "
            + "p = "
            + df.format(md.p)
            + ";");
    tAvK.setText(df.format(md.avK.getAve() / md.N) + "  ");
    tAvU.setText(df.format(md.avU.getAve() / md.N) + "  ");
    tTemp.setText(df.format((2 * md.K) / (3 * (md.N - 1))) + "  ");
    tAvp.setText(df.format(md.avp.getAve()) + "  ");
    canvas.refresh(md.getXWrap(), md.N, true, false);
    cpnl.repaint();
    spnl.repaint();

    try {

      PrintWriter wavefunc =
          new PrintWriter(new FileOutputStream(new File("energyData.txt"), true));
      wavefunc.print(md.E / md.N + " " + md.K / md.N + " " + md.U / md.N);
      wavefunc.println();
      wavefunc.close();
    } catch (IOException ex) {
    }

    try {

      PrintWriter tempwriter =
          new PrintWriter(new FileOutputStream(new File("tempData.txt"), true));
      tempwriter.print(df.format((2 * md.K) / (3 * (md.N - 1))));
      tempwriter.println();
      tempwriter.close();
    } catch (IOException ex) {
    }
  }
コード例 #11
0
ファイル: A.java プロジェクト: t8m8/AtCoder
  static void solve() {
    int r = in.nextInt();
    int c = in.nextInt();
    int sy = in.nextInt() - 1;
    int sx = in.nextInt() - 1;
    int gy = in.nextInt() - 1;
    int gx = in.nextInt() - 1;
    char[][] t = new char[r][c];
    for (int i = 0; i < r; i++) {
      t[i] = in.next().toCharArray();
    }

    ArrayDeque<int[]> que = new ArrayDeque<>();
    BitSet visited = new BitSet();

    que.add(new int[] {sy, sx, 0});
    visited.set(sy * c + sx);

    int[] dx = {0, 1, 0, -1};
    int[] dy = {1, 0, -1, 0};
    int[][] dist = new int[r][c];

    while (!que.isEmpty()) {
      int[] p = que.pollFirst();
      int cy = p[0];
      int cx = p[1];
      int d = p[2];
      dist[cy][cx] = d;

      for (int i = 0; i < 4; i++) {
        int ny = cy + dy[i];
        int nx = cx + dx[i];
        if (ny < 0 || nx < 0 || r <= ny || c <= nx) continue;
        if (visited.get(ny * c + nx) || t[ny][nx] == '#') continue;
        que.add(new int[] {ny, nx, d + 1});
        visited.set(ny * c + nx);
      }
    }

    out.println(dist[gy][gx]);
  }
コード例 #12
0
ファイル: AOJ2739.java プロジェクト: t8m8/AOJ
 static void solve() {
   int n = in.nextInt();
   int m = in.nextInt();
   int t = in.nextInt();
   int[] a = new int[n];
   for (int i = 0; i < n; i++) {
     a[i] = in.nextInt();
   }
   boolean[] f = new boolean[t * 2];
   for (int i = 0; i < n; i++) {
     for (int j = a[i] - m; j < a[i] + m; j++) {
       f[j] = true;
     }
   }
   int ans = 0;
   for (int i = 0; i < t; i++) {
     if (!f[i]) ans++;
   }
   dump(f);
   out.println(ans);
 }
コード例 #13
0
ファイル: B.java プロジェクト: t8m8/AtCoder
 static void solve() {
   long n = in.nextLong();
   long m = in.nextLong();
   long p = in.nextLong();
   out.println(modPow(n, p, m));
 }
コード例 #14
0
ファイル: browse_jsp.java プロジェクト: dalinhuang/daxieoa
  private void InitUpload() throws ServletException, IOException {
    String sConfig = myUtil.ReadFile(myUtil.getConfigFileRealPath(m_request.getServletPath()));
    ArrayList aStyle = myUtil.getConfigArray("Style", sConfig);

    String sAllowExt, sUploadDir, sBaseUrl, sContentPath;
    String sCurrDir, sDir;
    int nAllowBrowse;
    String sPathShareImage, sPathShareFlash, sPathShareMedia, sPathShareOther;

    // param
    String sType = myUtil.dealNull(m_request.getParameter("type")).toUpperCase();
    String sStyleName = myUtil.dealNull(m_request.getParameter("style"));
    String sCusDir = myUtil.dealNull(m_request.getParameter("cusdir"));
    String sAction = myUtil.dealNull(m_request.getParameter("action")).toUpperCase();

    String s_SKey = myUtil.dealNull(m_request.getParameter("skey"));

    // InitUpload

    String[] aStyleConfig = new String[1];
    boolean bValidStyle = false;

    for (int i = 0; i < aStyle.size(); i++) {
      aStyleConfig = myUtil.split(aStyle.get(i).toString(), "|||");
      if (sStyleName.toLowerCase().equals(aStyleConfig[0].toLowerCase())) {
        bValidStyle = true;
        break;
      }
    }

    if (!bValidStyle) {
      out.print(getOutScript("alert('Invalid Style!')"));
      out.close();
      return;
    }

    if (!aStyleConfig[61].equals("1")) {
      sCusDir = "";
    }

    String ss_FileSize = "",
        ss_FileBrowse = "",
        ss_SpaceSize = "",
        ss_SpacePath = "",
        ss_PathMode = "",
        ss_PathUpload = "",
        ss_PathCusDir = "",
        ss_PathCode = "",
        ss_PathView = "";
    if ((aStyleConfig[61].equals("2")) && (!s_SKey.equals(""))) {
      ss_FileSize =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileSize"));
      ss_FileBrowse =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileBrowse"));
      ss_SpaceSize =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpaceSize"));
      ss_SpacePath =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpacePath"));
      ss_PathMode =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathMode"));
      ss_PathUpload =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathUpload"));
      ss_PathCusDir =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCusDir"));
      ss_PathCode =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCode"));
      ss_PathView =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathView"));

      if (myUtil.IsInt(ss_FileSize)) {
        aStyleConfig[11] = ss_FileSize;
        aStyleConfig[12] = ss_FileSize;
        aStyleConfig[13] = ss_FileSize;
        aStyleConfig[14] = ss_FileSize;
        aStyleConfig[15] = ss_FileSize;
        aStyleConfig[45] = ss_FileSize;
      } else {
        ss_FileSize = "";
      }
      if (ss_FileBrowse.equals("0") || ss_FileBrowse.equals("1")) {
        aStyleConfig[43] = ss_FileBrowse;
      } else {
        ss_FileBrowse = "";
      }
      if (myUtil.IsInt(ss_SpaceSize)) {
        aStyleConfig[78] = ss_SpaceSize;
      } else {
        ss_SpaceSize = "";
      }
      if (!ss_PathMode.equals("")) {
        aStyleConfig[19] = ss_PathMode;
      }
      if (!ss_PathUpload.equals("")) {
        aStyleConfig[3] = ss_PathUpload;
      }
      if (!ss_PathCode.equals("")) {
        aStyleConfig[23] = ss_PathCode;
      }
      if (!ss_PathView.equals("")) {
        aStyleConfig[22] = ss_PathView;
      }

      sCusDir = ss_PathCusDir;
    }

    sBaseUrl = aStyleConfig[19];
    nAllowBrowse = Integer.valueOf(aStyleConfig[43]).intValue();

    if (nAllowBrowse != 1) {
      out.print(getOutScript("alert('Do not allow browse!')"));
      out.close();
      return;
    }

    if (!sCusDir.equals("")) {
      sCusDir = myUtil.replace(sCusDir, "\\", "/");
      if ((sCusDir.startsWith("/"))
          || (sCusDir.startsWith("."))
          || (sCusDir.endsWith("."))
          || (sCusDir.indexOf("./") >= 0)
          || (sCusDir.indexOf("/.") >= 0)
          || (sCusDir.indexOf("//") >= 0)
          || (sCusDir.indexOf("..") >= 0)) {
        sCusDir = "";
      } else {
        if (!sCusDir.endsWith("/")) {
          sCusDir = sCusDir + "/";
        }
      }
    }

    sUploadDir = aStyleConfig[3];
    if (!sBaseUrl.equals("3")) {
      sUploadDir = myUtil.getRealPathFromRelative(m_request.getServletPath(), sUploadDir);
    }
    sUploadDir = GetSlashPath(sUploadDir);
    sUploadDir =
        sUploadDir
            + myUtil.replace(myUtil.replace(sCusDir, "/", sFileSeparator), "\\", sFileSeparator);

    if (sType.equals("FILE")) {
      sAllowExt = aStyleConfig[6];
    } else if (sType.equals("MEDIA")) {
      sAllowExt = aStyleConfig[9];
    } else if (sType.equals("FLASH")) {
      sAllowExt = aStyleConfig[7];
    } else {
      sAllowExt = aStyleConfig[8];
    }

    sPathShareImage =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/image/"));
    sPathShareFlash =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/flash/"));
    sPathShareMedia =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/media/"));
    sPathShareOther =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/other/"));

    String s_Out = "";
    if (sAction.equals("FILE")) {

      String s_ReturnFlag = myUtil.dealNull(m_request.getParameter("returnflag"));
      String s_FolderType = myUtil.dealNull(m_request.getParameter("foldertype"));
      String s_Dir = myUtil.dealNull(m_request.getParameter("dir"));
      s_Dir = java.net.URLDecoder.decode(s_Dir, "UTF-" + "8");

      String s_CurrDir = "";
      if (s_FolderType.equals("upload")) {
        s_CurrDir = sUploadDir;
      } else if (s_FolderType.equals("shareimage")) {
        sAllowExt = "";
        s_CurrDir = sPathShareImage;
      } else if (s_FolderType.equals("shareflash")) {
        sAllowExt = "";
        s_CurrDir = sPathShareFlash;
      } else if (s_FolderType.equals("sharemedia")) {
        sAllowExt = "";
        s_CurrDir = sPathShareMedia;
      } else {
        s_FolderType = "shareother";
        sAllowExt = "";
        s_CurrDir = sPathShareOther;
      }

      s_Dir = myUtil.replace(s_Dir, "\\", "/");
      if ((s_Dir.startsWith("/"))
          || (s_Dir.startsWith("."))
          || (s_Dir.endsWith("."))
          || (s_Dir.indexOf("./") >= 0)
          || (s_Dir.indexOf("/.") >= 0)
          || (s_Dir.indexOf("//") >= 0)
          || (s_Dir.indexOf("..") >= 0)) {
        s_Dir = "";
      }

      String s_Dir2 = myUtil.replace(s_Dir, "/", sFileSeparator);
      s_Dir2 = myUtil.replace(s_Dir2, "\\", sFileSeparator);

      if (!s_Dir.equals("")) {
        if (CheckValidDir(s_CurrDir + s_Dir2)) {
          s_CurrDir += s_Dir2;
        } else {
          s_Dir = "";
        }
      }

      if (CheckValidDir(s_CurrDir)) {
        File file = new File(s_CurrDir);
        File[] filelist = file.listFiles();
        if (filelist != null && filelist.length > 0) {
          int n = -1;
          for (int i = 0; i < filelist.length; i++) {
            if (filelist[i].isFile()) {
              String s_FileName = filelist[i].getName();
              String s_FileExt = s_FileName.substring(s_FileName.lastIndexOf(".") + 1);
              s_FileExt = s_FileExt.toLowerCase();
              if (CheckValidExt(sAllowExt, s_FileExt)) {
                n++;
                s_Out =
                    s_Out
                        + "arr["
                        + String.valueOf(n)
                        + "]=new Array(\""
                        + s_FileName
                        + "\", \""
                        + String.valueOf(convertFileSize(filelist[i].length()))
                        + "\",\""
                        + formatDate(new Date(filelist[i].lastModified()))
                        + "\");\n";
              }
            }
          }
        }
      }

      s_Out =
          "var arr = new Array();\n"
              + s_Out
              + "parent.setFileList('"
              + s_ReturnFlag
              + "', '"
              + s_FolderType
              + "', '"
              + s_Dir
              + "', arr);";
      out.print(getOutScript(s_Out));

    } else {

      s_Out = "var arrUpload = new Array();\n";
      s_Out += "var arrShareImage = new Array();\n";
      s_Out += "var arrShareFlash = new Array();\n";
      s_Out += "var arrShareMedia = new Array();\n";
      s_Out += "var arrShareOther = new Array();\n";

      s_Out += GetFolderTree(sUploadDir, "Upload", 1, 0).get(0).toString();

      sAllowExt = "";
      if (sType.equals("FILE")) {
        s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareOther, "ShareOther", 1, 0).get(0).toString();
      } else if (sType.equals("MEDIA")) {
        s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString();
      } else if (sType.equals("FLASH")) {
        s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString();
      } else {
        s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString();
      }

      s_Out +=
          "parent.setFolderList(arrUpload, arrShareImage, arrShareFlash, arrShareMedia, arrShareOther);";
      out.print(getOutScript(s_Out));
    }
  }