Exemplo n.º 1
0
 void pln(String s) {
   try {
     bw.write(s);
     bw.write(System.lineSeparator());
   } catch (Exception ex) {
   }
 }
  public static void main(String[] args) throws Exception {

    /*  BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000);
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int q = Integer.parseInt(s[1]);
    int num[] = new int[n + 1];
    int[] m = new int[3 * n + 1]; // size = 2*n+1
    Arrays.fill(num, -1);
    s = br.readLine().split(" ");
    for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]);
    /// build tree
    maketree(1, 1, n, m, num);

    for (int qq = 1; qq <= q; qq++) {
      s = br.readLine().split(" ");
      int i = Integer.parseInt(s[0]);
      int j = Integer.parseInt(s[1]);
      int ans = query(1, 1, n, m, num, i, j);
      out.write("" + num[ans] + "\n");
      out.flush();
    }
  }
  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    // byte digit[]=new byte[101];
    // boolean[] check=new boolean[101];
    // int num[]=new int[99999];
    ans = 0;
    int tests = Integer.parseInt(br.readLine());
    BigInteger f[] = new BigInteger[101];

    for (int i = 1; i <= 100; i++) {
      f[i] = new BigInteger(("" + i));
    }
    for (int i = 2; i <= 100; i++) {
      f[i] = f[i].multiply(f[i - 1]);
    }

    for (int i = 0; i < tests; i++) {

      int n = Integer.parseInt(br.readLine());
      out.write("\n" + f[n].toString());
      out.flush();
    }
  }
Exemplo n.º 4
0
 public static boolean saveStringToFile(String filename, String data) {
   BufferedWriter writer = null;
   try {
     writer = new BufferedWriter(new FileWriter(filename));
     writer.write(data);
     writer.close();
   } catch (Exception e) {
     e.printStackTrace();
     if (writer != null)
       try {
         writer.close();
       } catch (Exception ee) {
       }
     return false;
   }
   return true;
 }
Exemplo n.º 5
0
 /** @param args */
 public static void main(String[] args) throws Exception {
   File file = new File("input.txt");
   if (file.exists()) {
     System.setIn(new BufferedInputStream(new FileInputStream("input.txt")));
   }
   out = System.out;
   bw = new BufferedWriter(new PrintWriter(out));
   // sc =  new Scanner(System.in);
   br = new BufferedReader(new InputStreamReader(System.in));
   C231 t = new C231();
   t.solve();
   bw.close();
 }
Exemplo n.º 6
0
  public void solve() throws Exception {

    String s = br.readLine();
    String[] sp = s.split(" ");
    int n = parseInt(sp[0]);
    int m = parseInt(sp[1]);
    int fl = 0;
    int hf = 0;
    int zr = 0;
    for (int i = 0; i < n; i++) {
      s = br.readLine();
      sp = s.split(" ");
      for (int j = 0; j < sp.length; j++) {
        if (sp[j].equals("11")) {
          fl++;
        } else if (sp[j].equals("00")) {
          zr++;
        } else {
          hf++;
        }
      }
    }
    int[][] ans = new int[n][m];
    int fla = fl % m;
    int row = 0;
    int col = 0;
    if (fl > 0) {
      for (row = 0; row < n; row++) {
        for (col = 0; col < m; col++) {
          ans[row][col] = 1;
          fl--;
          if (fl == 0) {
            break;
          }
        }
        if (fl == 0) {
          break;
        }
      }
      col++;
    }

    if (col == m) {
      row++;
      col = 0;
    }
    if (hf > 0) {
      for (int j = m - 1; j >= col; j--) {
        ans[row][j] = 2;
        hf--;
        if (hf == 0) {
          break;
        }
      }
    }
    boolean flag = true;
    for (int i = n - 1; i >= 0; i--) {
      if (hf == 0) break;
      for (int j = m - 1; j >= 0; j--) {
        if (flag) {
          ans[i][j] = 3;
        } else {
          ans[i][j] = 2;
        }
        hf--;
        if (hf == 0) break;
      }
      flag = !flag;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j != 0) {
          bw.write(" ");
        }
        if (ans[i][j] == 1) {
          bw.write("11");
        } else if (ans[i][j] == 2) {
          bw.write("01");
        } else if (ans[i][j] == 3) {
          bw.write("10");
        } else {
          bw.write("00");
        }
      }
      bw.write("\n");
    }
  }
Exemplo n.º 7
0
 void pl(String s) {
   try {
     bw.write(s);
   } catch (Exception ex) {
   }
 }