コード例 #1
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();
 }
コード例 #2
0
ファイル: Beta013E.java プロジェクト: hiroshi-cl/wakaba
 public void run() {
   // Scanner sc = new Scanner(System.in);
   Scanner sc = new Scanner();
   StringBuilder sb = new StringBuilder(1000000);
   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
   final int N = sc.nextInt();
   final int M = sc.nextInt();
   final int K = (int) floor(sqrt(N));
   final int[] A = new int[N + 1];
   A[0] = 1;
   for (int i = 1; i <= N; i++) A[i] = sc.nextInt();
   final int[] next = new int[N + 1];
   final int[] step = new int[N + 1];
   final int[] last = new int[N + 1];
   for (int i = N; i > 0; i--) {
     int j = i + A[i];
     if (j > N || j / K > i / K) {
       last[i] = i;
       step[i] = 1;
       next[i] = j;
     } else {
       last[i] = last[j];
       step[i] = step[j] + 1;
       next[i] = next[j];
     }
   }
   for (int t = 0; t < M; t++)
     if (sc.nextInt() == 1) {
       int i = sc.nextInt();
       int j = 0;
       int k = 0;
       while (i <= N) {
         j += step[i];
         k = last[i];
         i = next[i];
       }
       sb.append(k).append(' ').append(j).append('\n');
       // System.out.println(k + " " + j);
     } else {
       int k = sc.nextInt();
       int b = k / K * K;
       A[k] = sc.nextInt();
       for (int i = min(b + K - 1, N); i >= b; i--) {
         int j = i + A[i];
         if (j > N || j / K > i / K) {
           last[i] = i;
           step[i] = 1;
           next[i] = j;
         } else {
           last[i] = last[j];
           step[i] = step[j] + 1;
           next[i] = next[j];
         }
       }
     }
   // System.out.flush();
   System.out.print(sb);
 }
 public String ns() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != // ' ')
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
コード例 #4
0
 private String ns1() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b) && b != ' ')) { // when nextLine,
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
コード例 #5
0
 /**
  * Returns the {@code String} representation of the given collection, or {@code null} if the given
  * collection is {@code null}.
  *
  * @param c the collection to format.
  * @return the {@code String} representation of the given collection.
  */
 public static String format(Collection<?> c) {
   if (c == null) return null;
   Iterator<?> i = c.iterator();
   if (!i.hasNext()) return "[]";
   StringBuilder b = new StringBuilder();
   b.append('[');
   for (; ; ) {
     Object e = i.next();
     b.append(e == c ? "(this Collection)" : toStringOf(e));
     if (!i.hasNext()) return b.append(']').toString();
     b.append(", ");
   }
 }
コード例 #6
0
 protected void addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) {
   StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend();
   if (importDeclarationsToAppend.length() == 0) return;
   importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
   importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource);
   int insertOffset = importRegion.getOffset() + importRegion.getLength();
   if (insertOffset != 0 && originalImportDeclarations.isEmpty())
     importDeclarationsToAppend.insert(0, lineSeparator);
   importDeclarationsToAppend.append(lineSeparator);
   int insertLength = -importRegion.getLength();
   insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength();
   ReplaceRegion appendDeclarations =
       new ReplaceRegion(
           new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString());
   acceptor.accept(appendDeclarations);
 }
コード例 #7
0
 protected boolean appendSubsection(
     StringBuilder builder, Iterable<XImportDeclaration> subSection, boolean needsNewline) {
   if (!isEmpty(subSection)) {
     if (needsNewline) builder.append(lineSeparator);
     for (XImportDeclaration declaration : isSort() ? sort(subSection) : subSection) {
       appendImport(builder, declaration);
     }
     return true;
   }
   return needsNewline;
 }
コード例 #8
0
 protected String serializeImports(List<XImportDeclaration> allDeclarations) {
   StringBuilder builder = new StringBuilder();
   if (needsPreceedingBlankLine()) builder.append(lineSeparator).append(lineSeparator);
   boolean needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return !input.isStatic();
                 }
               }),
           false);
   needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return input.isStatic() && !input.isExtension();
                 }
               }),
           needNewline);
   appendSubsection(
       builder,
       filter(
           allDeclarations,
           new Predicate<XImportDeclaration>() {
             @Override
             public boolean apply(XImportDeclaration input) {
               return input.isStatic() && input.isExtension();
             }
           }),
       needNewline);
   if (!isEmpty(allDeclarations)) builder.append(lineSeparator);
   return builder.toString();
 }
コード例 #9
0
 protected void appendImport(StringBuilder builder, XImportDeclaration newImportDeclaration) {
   builder.append("import ");
   if (newImportDeclaration.isStatic()) {
     builder.append("static ");
     if (newImportDeclaration.isExtension()) {
       builder.append("extension ");
     }
   }
   String qualifiedTypeName = newImportDeclaration.getImportedNamespace();
   if (newImportDeclaration.getImportedType() != null) {
     qualifiedTypeName = serializeType(newImportDeclaration.getImportedType());
   }
   String escapedTypeName = nameValueConverter.toString(qualifiedTypeName);
   builder.append(escapedTypeName);
   if (newImportDeclaration.isStatic()) {
     builder.append(".");
     if (newImportDeclaration.isWildcard()) {
       builder.append("*");
     } else {
       builder.append(newImportDeclaration.getMemberName());
     }
   }
   builder.append(lineSeparator);
 }
コード例 #10
0
ファイル: MP1.java プロジェクト: Yamunathangam/MP1
  public String[] process() throws Exception {
    String[] ret = new String[20];

    String s[][] = new String[30][200];
    String st = "";
    File filepath = new File(inputFileName);
    FileInputStream fin = new FileInputStream(filepath);
    // FileInputStream fin1=new FileInputStream(filepath);
    int i, j = 0, k = 0, count = 1;

    String st1 = "", st2 = "";
    List l = new ArrayList();
    while ((i = fin.read()) != -1) {

      st = st + (char) i;
      char c = (char) i;
      if (c == '\n') {
        StringTokenizer str = new StringTokenizer(st, delimiters);
        while (str.hasMoreTokens()) {
          StringBuilder sb = new StringBuilder(str.nextToken().toLowerCase().trim());
          // if(Character.isWhitespace(sb.charAt(0)))
          // System.out.print("hello");
          String stt = sb.toString();
          l.add(stt);
          count++;
        }

        st = "";
      }
    }

    HashSet m = new HashSet();
    Collections.sort(l);
    System.out.println(l);
    j = 1;
    for (int f = 0; f < count - 1; f++) {
      String st5 = l.get(f).toString();
      for (int ft = 0; ft < count - 1; ft++) {
        String st6 = l.get(ft).toString();
        if (st5.equalsIgnoreCase(st6)) {
          ++k;
        }
      }

      // System.out.println(l.get(f).toString()+k);
      m.add((st5 + k));
      k = 0;

      // j++;

    }
    // System.out.println(t.toString()+count);ject

    // Collection stmap = m.values()

    Iterator itr = m.iterator();
    while (itr.hasNext()) System.out.println(itr.next());
    System.out.println("finished");
    // TODO

    return ret;
  }