Exemple #1
1
 public static void main(String[] args) {
   Scanner scanner = new Scanner(System.in);
   int m = scanner.nextInt();
   assert 1 <= m && m <= 100 : "out of range, m: " + m;
   int s = scanner.nextInt();
   assert 0 <= s && s <= 900 : "out of range, s: " + s;
   if (s > 9 * m || (s == 0 && m > 1)) {
     System.out.println("-1 -1");
     return;
   }
   if (m == 1 && s == 0) {
     System.out.println("0 0");
     return;
   }
   StringBuilder sb = new StringBuilder();
   int l = 0;
   for (int i = 0; i < m; i++) {
     int d = (s >= 9) ? 9 : s;
     sb.append(d);
     s -= d;
     if (d != 0) {
       l = i;
     }
   }
   String large = sb.toString();
   if (sb.charAt(m - 1) == '0') {
     sb.setCharAt(l, (char) (sb.charAt(l) - 1));
     sb.setCharAt(m - 1, '1');
   }
   String small = sb.reverse().toString();
   System.out.printf("%s %s", small, large);
 }
Exemple #2
0
 public static void main(String[] args) throws IOException {
   Scanner s = new Scanner(new File("gift1.in"));
   PrintWriter out = new PrintWriter(new FileWriter("gift1.out"));
   int people = s.nextInt();
   HashMap<String, Integer> moneyGiven = new HashMap<String, Integer>();
   HashMap<String, Integer> moneyReceived = new HashMap<String, Integer>();
   String[] names = new String[people];
   for (int x = 0; x < people; x++) {
     String name = s.next();
     names[x] = name;
     moneyGiven.put(name, 0);
     moneyReceived.put(name, 0);
   }
   for (int x = 0; x < people; x++) {
     String person = s.next();
     int give = s.nextInt();
     int receivers = s.nextInt();
     if (receivers == 0) continue;
     give = give - give % receivers;
     moneyGiven.put(person, give);
     for (int y = 0; y < receivers; y++) {
       String name = s.next();
       moneyReceived.put(name, give / receivers + moneyReceived.get(name));
     }
   }
   for (int x = 0; x < people; x++) {
     out.println(names[x] + " " + (moneyReceived.get(names[x]) - moneyGiven.get(names[x])));
   }
   out.close();
 }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();

    long d3 = 3, d5 = 5, d15 = 15;
    long n3 = 0, n5 = 0, n15 = 0;
    if ((1 <= T) && (T <= 100000)) {
      for (int j = 0; j < T; j++) {
        long sum3 = 0, sum5 = 0, sum15 = 0, sum = 0;
        long l3, l5, l15 = 0;

        int N = sc.nextInt();
        if ((1 <= N) && (N <= 1000000000)) {
          N = N - 1;
          l3 = N % 3;
          l3 = N - l3;
          n3 = (l3 - 3) / 3 + 1;
          sum3 = (3 * ((n3) + 1) * (n3)) / 2;

          l5 = N % 5;
          l5 = N - l5;
          n5 = (l5 - 5) / 5 + 1;
          sum5 = (5 * ((n5) + 1) * (n5)) / 2;

          l15 = N % 15;
          l15 = N - l15;
          n15 = (l15 - 15) / 15 + 1;
          sum15 = (15 * ((n15) + 1) * (n15)) / 2;

          sum = sum3 + sum5 - sum15;
          System.out.println(sum);
        }
      }
    }
  }
Exemple #4
0
  public static void main(String args[]) {
    Scanner cin = new Scanner(System.in);

    int num = cin.nextInt();
    for (int i = 0; i < num; i++) {
      int policy = cin.nextInt();
      int english = cin.nextInt();
      int math = cin.nextInt();
      int major = cin.nextInt();

      int total = policy + english + math + major;
      // 如果是Fail
      if (policy < 60 || english < 60 || math < 90 || major < 90 || total < 310) {
        System.out.println("Fail");
      }
      // 如果是Zifei
      else if (total < 350) {
        System.out.println("Zifei");
      }
      // 如果是Gongfei
      else {
        System.out.println("Gongfei");
      }
    }
  }
 public static void main(String[] args) throws FileNotFoundException {
   Scanner sc = new Scanner(new File("J.in"));
   for (int z = 1; ; z++) {
     int R = sc.nextInt();
     int T = sc.nextInt();
     if (R == 0 && T == 0) break;
     int[][] flow = new int[R + 3][R + 3];
     int s = flow.length - 2;
     int e = flow.length - 1;
     for (int i = 0; i < T; i++) {
       int a = sc.nextInt();
       int b = sc.nextInt();
       flow[a][b]++;
       flow[b][a]++;
     }
     flow[0][e] = 100000000;
     int[] cost = new int[R + 1];
     for (int i = 0; i < cost.length; i++) {
       if (i == 0) cost[0] = Integer.MAX_VALUE;
       else {
         int[][] fl = new int[R + 3][R + 3];
         for (int j = 0; j < fl.length; j++)
           for (int k = 0; k < fl.length; k++) fl[j][k] = flow[j][k];
         fl[s][i] = 100000000;
         cost[i] = maxflow(s, e, fl);
       }
     }
     // System.out.println(Arrays.toString(cost));
     int f = dijkstra(1, 0, cost, flow);
     System.out.println("Case " + z + ": " + f + "\n");
   }
 }
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    TreeMap<Long, Long> tmap = new TreeMap<>();
    long res = 0;
    while (t-- > 0) {
      res = 0;
      int n = in.nextInt();
      long m = in.nextLong();
      tmap.clear();
      long[] arr = new long[n];
      res = in.nextLong();
      arr[0] = res % m;
      res = Long.MIN_VALUE;
      tmap.put(arr[0], arr[0]);
      for (int i = 1; i < arr.length; i++) {
        arr[i] = in.nextLong();
        arr[i] %= m;
        arr[i] += arr[i - 1];
        arr[i] %= m;

        if (tmap.higherEntry(arr[i]) == null) {
          res = Math.max(res, arr[i]);
          tmap.put(arr[i], arr[i]);
          continue;
        }
        long val = tmap.higherEntry(arr[i]).getValue();
        res = Math.max(res, (arr[i] - val + m) % m);
        tmap.put(arr[i], arr[i]);
      }

      System.out.println(res);
    }
  }
Exemple #7
0
  public static void main(String args[]) {
    int N;
    Scanner in = new Scanner(System.in);
    N = in.nextInt();
    int arr[] = new int[N];
    ArrayList even = new ArrayList();
    ArrayList odd = new ArrayList();
    ArrayList list = new ArrayList();

    for (int i = 0; i < N; i++) {
      arr[i] = in.nextInt();
    }
    int evenSum = 0;
    int oddSum = 0;
    for (int i = 0; i < N; i++) {
      if (arr[i] % 2 == 0) {
        even.add(arr[i]);
        evenSum = evenSum + arr[i];
      } else {
        odd.add(arr[i]);
        oddSum = oddSum + arr[i];
      }
    }
    even.add(evenSum);
    odd.add(oddSum);
    Collections.sort(even);
    Collections.sort(odd);
    list.addAll(even);
    list.addAll(odd);
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
      System.out.println(itr.next());
    }
  }
  public static void modificarDatosAlumno(ArrayList arrayL) {
    int matricula = 0;
    Scanner tec = new Scanner(System.in);
    System.out.println("Introduzca la matricula del alumno a modificar: ");
    matricula = tec.nextInt();
    tec.nextLine();
    Alumno alum1;

    alum1 = buscarAlumnoPorMatricula(arrayL, matricula);

    if (alum1 != null) {
      System.out.println("Alumno encontrado que desea modificar: ");
      int opcion1 = 0;

      while (opcion1 < 10) {
        System.out.println("1- Modificar Numero de matricula");
        System.out.println("2- Modificar Nombre");
        System.out.println("3- Modificar telefono");
        System.out.println("4- Modificar apellido");
        System.out.println("10- salir");
        opcion1 = tec.nextInt();
        tec.nextLine();

        switch (opcion1) {
          case 1:
            int mat = 0;
            System.out.println("Introduzca el nuevo numero de matricula");
            alum1.setMatricula(matricula);
            break;
        }
      }

    } else System.out.println("Esta matricula no corresponde a ningun alumno");
  }
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

    try {

      Scanner sc = new Scanner(new File("/home/santosh/Desktop/testData"));

      int testCases = sc.nextInt();
      int i = 0;
      ArrayList<ArrayList<Integer>> inputArraysList = new ArrayList<ArrayList<Integer>>();
      ArrayList<Integer> list;
      while (i++ < testCases) {

        int n = sc.nextInt();
        int k = 0;
        list = new ArrayList<Integer>();
        while (k < n) {
          list.add(sc.nextInt());
          k++;
        }
        inputArraysList.add(list);
      }

      // System.out.println(inputArraysList.size());
      for (ArrayList<Integer> arr : inputArraysList) {
        countPairs(arr.toArray(new Integer[arr.size()]));
      }

    } catch (Exception e) {

    }
  }
Exemple #10
0
  /* Helpers */
  private static InputArgs input() throws IOException {
    System.out.println("2.2 Return Kth to Last");

    // read K
    System.out.print("Please input K: ");
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();

    // read number of nodes
    System.out.println();
    System.out.print("Please input the number of nodes in the linked list: ");
    int n = sc.nextInt();

    // read linked list
    System.out.println();
    System.out.print("Please input value of nodes (seperate by space, e.g., 1 2 3): ");

    ListNode dummy = new ListNode(0);
    ListNode pre = dummy;
    for (int i = 0; i < n; i++) {
      ListNode cur = new ListNode(sc.nextInt());
      pre.next = cur;
      pre = cur;
    }

    return new InputArgs(k, dummy.next);
  }
Exemple #11
0
  public void solve() throws Exception {
    int n = in.nextInt();
    int[] a = new int[n];
    int sum = 0;

    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
      sum += a[i];
    }

    sum /= 2;

    boolean[] dp = new boolean[sum + 1];
    dp[0] = true;

    for (int tmp : a) {
      for (int i = sum; i >= tmp; i--) {
        if (dp[i - tmp]) {
          dp[i] = true;
        }
      }
    }

    String ans = dp[sum] ? "YES" : "NO";
    out.println(ans);
  }
Exemple #12
0
  /**
   * Build Sample Method. Builds a simulation of a biological sample. Data is read in from a file to
   * create the sample, then the sample simulation data is stored in the two dimensional arrays:
   * Dish, DishCur, and DishFut.
   *
   * @param No Parameters
   * @return void - Does not return a value
   * @exception FileNotFoundException
   */
  public void buildSample() throws FileNotFoundException {
    try {
      Scanner InFile = new Scanner(new File(this.Input));

      this.Gen = InFile.nextInt();

      for (int i = 0; i < MaxK; i++) {
        this.D[i] = InFile.nextInt();
      }

      for (int r = 0; r < LoopBounds; r++) {
        for (int c = 0; c < LoopBounds; c++) {
          this.Dish[r][c] = InFile.nextInt();
        }
      }

      InFile.close();

      for (int r = 0; r < LoopBounds; r++) {
        for (int c = 0; c < LoopBounds; c++) {
          DishCur[r][c] = this.Dish[r][c];
        }
      }

      for (int r = 0; r < LoopBounds; r++) {
        for (int c = 0; c < LoopBounds; c++) {
          DishFut[r][c] = DishCur[r][c];
        }
      }

    } catch (Exception E) {
      System.out.println("Something went wrong reading from file");
    }
  }
  /*
   * Similar to makeSureValInRange function except it is meant to return
   * more than one values of valid user input via LinkedList and it will
   * not return unless all of the input is valid
   * @param1 scanner object
   * @param2 lowerbound int
   * @param3 upperbound int
   * @param4 String that represents the entity we are entering the values for
   */
  public static LinkedList<Integer> makeSureValInRange2(
      Scanner scan, int lowerbound, int upperbound, String inputFor) {
    assert (lowerbound <= upperbound);
    LinkedList<Integer> list = new LinkedList<Integer>();
    System.out.println(
        SearchCriteria.prioritySetUpString(
            SearchCriteria.StringEnum.SELECT_CRITERIA, inputFor)); // prints the options to the user
    int value = scan.nextInt();
    if (valInRange(lowerbound, upperbound, value)) {
      list.add(value); // If the first inputted is in range then we add more values

      boolean done = false;
      int i = lowerbound;
      while (!done
          && i < upperbound) { // keep looking for input until user enters a duplicate value
        // or the LinkedList of input is full
        value = scan.nextInt();
        if (!list.contains(value) && valInRange(lowerbound, upperbound, value)) list.add(value);
        else done = true;
        i++;
      }
      return list;
    } else { // If the first value intered is not valid, then we return a null, which means that
      // we use default values (all values within range)
      System.out.println(
          SearchCriteria.prioritySetUpString(SearchCriteria.StringEnum.DEFAULT, inputFor));
      return null;
    }
  }
Exemple #14
0
 public static void main(String[] args) throws Exception {
   Scanner sc = new Scanner(new File("B.in"));
   System.setOut(new PrintStream("B.out"));
   //		sc = new Scanner(System.in);
   List<Integer> pr = new ArrayList<Integer>();
   boolean[] comp = new boolean[300000];
   for (int i = 2; i < 550; i++) {
     if (p(i) && !comp[i]) {
       for (int j = 2; i * j < 300000; j++) {
         comp[i * j] = true;
       }
       pr.add(i);
     }
   }
   for (int i = 550; i < 300000; i++) {
     if (p(i) && !comp[i]) pr.add(i);
   }
   // System.out.println(pr);
   for (int n = sc.nextInt(); n != 1; n = sc.nextInt()) {
     System.out.print(n + ":");
     for (int i = 0; i < pr.size(); i++) {
       if (n % pr.get(i) == 0) System.out.print(" " + pr.get(i));
     }
     System.out.println();
   }
 }
 public static void main(String[] args) throws IOException {
   Scanner scan = new Scanner(/*System.in*/ new File("ariprog.in"));
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ariprog.out")));
   int length = scan.nextInt();
   int max = scan.nextInt();
   int[] squares = new int[(max) * max * 2 + 1];
   // ArrayList<Integer> squares = new ArrayList<Integer>();
   for (int i = 0; i <= max; i++) {
     for (int j = i; j <= max; j++) {
       squares[i * i + j * j] = 1;
     }
   }
   ArrayList<Integer> starts = new ArrayList<Integer>();
   ArrayList<Integer> diffs = new ArrayList<Integer>();
   boolean has = false;
   for (int diff = 1; diff <= ((max * max * 2 / (length - 1))); diff++) {
     for (int start = 0; start < squares.length - length; start++) {
       if (squares[start] == 1) {
         if (check(diff, start, squares, length)) {
           starts.add(start);
           diffs.add(diff);
           // out.println(squares[start] + " " + diff);
           has = true;
         }
       }
     }
   }
   remove(starts, diffs);
   for (int i = 0; i < starts.size(); i++) {
     /*System.*/ out.println(starts.get(i) + " " + diffs.get(i));
   }
   if (!has) /*System.*/ out.println("NONE");
   out.close();
   System.exit(0);
 }
 public static void main(String... orange) throws IOException {
   Scanner scan = new Scanner(new File("barn1.in"));
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("barn1.out")));
   int bars = scan.nextInt();
   int total = scan.nextInt();
   int have = scan.nextInt();
   ArrayList<Integer> values = new ArrayList<Integer>();
   ArrayList<Integer> locations = new ArrayList<Integer>();
   for (int i = 0; i < have; i++) {
     values.add(scan.nextInt());
   }
   Collections.sort(values);
   int first = values.get(0);
   for (int i = 1; i < have; i++) {
     int current = values.get(i);
     locations.add(current - first);
     first = current;
   }
   if (bars >= have) {
     out.println(have);
   } else {
     for (int i = 0; i < bars - 1; i++) {
       locations.remove(Collections.max(locations));
     }
     int sum = 0;
     for (int i = 0; i < locations.size(); i++) sum += locations.get(i);
     sum += bars;
     out.println(sum);
   }
   out.close();
   System.exit(0);
 }
Exemple #17
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   // keep this function call here
   Scanner s = new Scanner(System.in);
   Function8 c = new Function8();
   System.out.print(c.CheckNums(s.nextInt(), s.nextInt()));
 }
Exemple #18
0
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    Scanner in = new Scanner(System.in);

    int N = in.nextInt();

    Node[] nodes = new Node[N];

    for (int i = 0; i < N; i++) {
      nodes[i] = new Node(i + 1);
    }

    for (int i = 0; i < N; i++) {
      int a = in.nextInt();
      int b = in.nextInt();

      Node n = nodes[i];

      if (a != -1) n.left = nodes[a - 1];
      if (b != -1) n.right = nodes[b - 1];
    }

    int T = in.nextInt();

    for (int i = 0; i < T; i++) {
      int K = in.nextInt();

      swap(nodes[0], K, 1);

      Inorder(nodes[0]);
      System.out.println("");
    }
  }
Exemple #19
0
 public static void main(String[] args) throws Exception {
   long[] ans = new long[30];
   ans[1] = 1;
   ans[2] = 9;
   ans[3] = 89;
   ans[4] = 89;
   long step = 500;
   for (int i = 5; i <= 20; ++i) {
     long now = ans[i - 1];
     while (!check(now, i)) now += step;
     ans[i] = now;
     //	System.out.println(ans[i]);
     step *= 5;
   }
   for (int i = 1; i <= 20; ++i) {
     System.out.printf("a[%d]=%dll;\n", i, ans[i]);
   }
   Scanner cin = new Scanner(new BufferedInputStream(System.in));
   int tests = cin.nextInt();
   int ca = 0;
   while (tests-- > 0) {
     int n = cin.nextInt();
     System.out.printf("%d %d ", ++ca, n);
     System.out.println(ans[n]);
   }
 }
  public void load(File target) {
    try {
      Scanner input = new Scanner(target);
      // Loads in the initial information, resets some values, such as scores, as well
      sideLength_ = input.nextInt();
      currentPlayer_ = input.nextInt();
      board_ = new int[sideLength_][sideLength_];
      totalMovesPossible_ = (sideLength_ - 2) * (sideLength_ - 2) - 4;
      p1Score_ = 0;
      p2Score_ = 0;
      emptySpacesLeft_ = 0;

      input.nextLine(); // Extra nextLine method to get past the first two lines
      for (int y = 0; input.hasNextLine(); y++) {
        String[] stringLine = input.nextLine().split(valueSeparator_);
        for (int x = 0; x < stringLine.length; x++) {
          int value = Integer.parseInt(stringLine[x]);
          board_[x][y] = value;
          if (value == 1) {
            p1Score_++;
          } else if (value == 2) {
            p2Score_++;
          } else if (value == 0) {
            emptySpacesLeft_++;
          }
        }
      }
      input.close();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
  public static int[][] getData(String fileName) {

    Vector<String> dataSet = new Vector<String>();
    String oneLine = "";
    int[][] data = new int[1][1];

    try {
      Scanner sc = new Scanner(new File(fileName));
      while (sc.hasNextLine()) {
        oneLine = sc.nextLine();
        dataSet.add(oneLine);
      }
      sc.close();
      int row = dataSet.size() - 1;
      data = new int[row][2];
      for (int i = 1; i < row + 1; i++) {
        sc = new Scanner(dataSet.elementAt(i)).useDelimiter(" ");
        data[i - 1][1] = sc.nextInt();
        for (int j = 0; j < 2; j++) {
          sc.next();
        }
        data[i - 1][0] = sc.nextInt();
        sc.close();
      }
      sc.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }
    return data;
  }
Exemple #22
0
  public static void main(String[] args) {
    // Declarations.
    Scanner sc = new Scanner(System.in);
    int CASES = 0;

    // Load values
    CASES = sc.nextInt();

    // Iterate test cases
    for (int i = 0; i < CASES; i++) {

      // Declare values
      int Px, Py, Qx, Qy, Sx, Sy, difX, difY;

      // Load Values
      Px = sc.nextInt();
      Py = sc.nextInt();
      Qx = sc.nextInt();
      Qy = sc.nextInt();

      // Calculate the diffrence
      difX = Qx - Px;
      difY = Qy - Py;

      // Calculate Symmetric points
      Sx = Px + (2 * difX);
      Sy = Py + (2 * difY);

      // Print the Symmetric points
      System.out.println(Sx + " " + Sy);
    }
  }
Exemple #23
0
 public static void readInput() {
   n = sc.nextInt();
   fibI = new int[n];
   for (int i = 0; i < n; i++) fibI[i] = sc.nextInt();
   sc.nextLine();
   cipher = sc.nextLine().replaceAll("[^A-Z]", "");
 }
  public static void main(String[] args) throws IOException {

    LinkedList<char[]> items = new LinkedList<char[]>();

    Scanner kb = new Scanner(System.in);
    System.out.println("Enter the number of Set N: ");
    int numN = kb.nextInt();

    System.out.println("Enter the number of Set R: ");
    int numR = kb.nextInt();

    char[] item = new char[numR];
    char[] input = new char[numN]; // new char[numN+1];

    /* input[0]='a';
    input[1]='b';
    input[2]='c';  */

    for (int i = 0; i <= numN - 1; i++) {
      System.out.println("Entre value of N" + (i + 1) + " :");
      input[i] = kb.next().charAt(0);
    }

    comWrep(items, input, item, 0);

    for (char[] c : items) {
      System.out.println(c);
    }
  }
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int M = sc.nextInt();
   int N = sc.nextInt();
   int a[][] = new int[M + 1][N + 1];
   int dp[][] = new int[M + 1][N + 1];
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       a[i][j] = sc.nextInt();
       if (a[i][j] == 0) a[i][j] = -9999999;
     }
   }
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
     }
   }
   int max = -100000000;
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       for (int k = 1; k <= M; k++) {
         if (i + k > M) break;
         else if (j + k > N) break;
         int temp = dp[i + k][j + k] - dp[i - 1][j + k] - dp[i + k][j - 1] + dp[i - 1][j - 1];
         max = Math.max(max, temp);
       }
     }
   }
   System.out.println(max);
 }
Exemple #26
0
  public static void main(String[] args) throws IOException {

    // reads in text file
    Scanner file = new Scanner(new FileReader("input.txt"));
    String message = file.useDelimiter("\\A").next();

    // capitalizes all letters and gets rid of blank spaces
    message = message.toUpperCase();
    message = message.replaceAll("\\s+", "");

    int cipher, encrypt_decrypt;

    // asks user of they want to encrypt or decrypt a message
    System.out.println("Do you want to encrypt or decrypt?");
    System.out.println("1 - Encrypt a message");
    System.out.println("2 - Decrypt a message");
    encrypt_decrypt = cin.nextInt();

    // asks user which algorithm to use
    System.out.println("Which cipher do you want to use?");
    System.out.println("1 - Shift Cipher");
    System.out.println("2 - Affine Cipher");
    System.out.println("3 - Substitution Cipher");
    System.out.println("4 - Vigenere Cipher");
    cipher = cin.nextInt();

    ciphers(message, cipher, encrypt_decrypt);
  }
Exemple #27
0
  /** Reads in the letter location data for the word hunt puzzle */
  public static void readPuzzle() {
    letters = new String[3][3][2];

    try {
      Scanner reader = new Scanner(new File("graph.txt"));

      while (reader.hasNext()) {
        String temp = reader.next();
        // if the String is not a number it is a character
        if (!NUMBERS.contains(temp)) {
          // find the coordinates of the letter/String
          int x = reader.nextInt();
          int y = reader.nextInt();
          int z = reader.nextInt();
          letters[x][y][z] = temp;
        }
      }

      // prints out the word hunt set up, in separate squares that represent the 2D arrays at each
      // depth
      for (int k = 0; k < 2; k++) {
        for (int i = 0; i < 3; i++) {
          for (int j = 0; j < 3; j++) {
            System.out.print(letters[i][j][k] + " ");
          }
          System.out.print("\n");
        }
        System.out.print("\n");
      }
    } catch (FileNotFoundException e) {
      System.out.println("No such file.");
    }
  }
Exemple #28
0
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int testcases = sc.nextInt();
    int d, v, u;
    double stime, spath;
    for (int i = 0; i < testcases; i++) {
      d = sc.nextInt();
      v = sc.nextInt();
      u = sc.nextInt();
      if (v == 0) {
        System.out.println("Case " + (i + 1) + ": can't determine");
        continue;
      }
      if (u <= v) {
        System.out.println("Case " + (i + 1) + ": can't determine");
        continue;
      }
      if (u == 0) {
        System.out.println("Case " + (i + 1) + ": can't determine");
        continue;
      }

      stime = (d + 0.0) / u;
      spath = (d + 0.0) / (Math.pow(u * u - v * v, 0.5));

      System.out.printf("Case %d: %.3f\n", i + 1, spath - stime);
    }
  }
Exemple #29
0
  public static void main(String args[]) throws Exception {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */

    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    SuperStack stack = new SuperStack();
    PrintWriter out = new PrintWriter(System.out, true);
    for (int i = 0; i < n; i++) {
      String s = in.next();
      if (s.equals("push")) {
        int value = in.nextInt();
        out.println(stack.push(value));
      } else if (s.equals("pop")) {
        int res = stack.pop();
        if (stack.size == 0) {
          out.println("EMPTY");
        } else {
          out.println(res);
        }
      } else if (s.equals("inc")) {
        int x = in.nextInt();
        int d = in.nextInt();
        out.println(stack.inc(x, d));
      }
    }
    out.close();
  }
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		double limit;
		while (test-- > 0) {
			limit = scan.nextDouble();
			n = scan.nextInt();
			V = 0;
			mm = new int[n];
			pp = new float[n];
			for (int i = 0; i < n; i++) {
				mm[i] = scan.nextInt();
				pp[i] = scan.nextFloat();
				V += mm[i];
			}
			dp = new float[V + 1];
			Arrays.fill(dp, 0);
			dp[0] = 1;
			for (int i = 0; i < n; i++)
				ZeroPack(mm[i], 1 - pp[i]);

			for (int i = V; i >= 0; i--)
				if (dp[i] > 1 - limit) {
					out.println(i);
					break;
				}

		}
		out.flush();
		out.close();
	}