コード例 #1
1
ファイル: Charlie.java プロジェクト: cohadar/codeforces
 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);
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: SKYLINE.java プロジェクト: soofyhbk2007/workspace
  public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int t = sc.nextInt();
    while (t-- > 0) {
      int n = sc.nextInt();
      int N = 1;
      while (N < 100001) N <<= 1; // padding
      SegmentTree st = new SegmentTree(N + 1);

      int ans = 0;
      for (int i = 0; i < n; i++) {
        int l = sc.nextInt(), r = sc.nextInt(), h = sc.nextInt();
        int tm = st.query(l, r - 1, h);
        st.update_range(l, r - 1, h);
        ans += tm;
      }

      out.println(ans);
    }

    out.flush();
    out.close();
  }
コード例 #4
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    // Read in the number of elements
    int n = in.nextInt();

    // Store the list of cities in an array
    int[] cities = new int[n];
    for (int i = 0; i < n; i++) {
      cities[i] = in.nextInt();
    }

    // Since the list is in ascending order (as specified in the problem
    // statement), the minimum difference will be to either the left or right
    // of the element, and the maximum will either be to the first or last
    // element
    for (int i = 0; i < n; i++) {
      int left = Integer.MAX_VALUE;
      int right = Integer.MAX_VALUE;
      if (i > 0) {
        left = Math.abs(cities[i] - cities[i - 1]);
      }
      if (i < n - 1) {
        right = Math.abs(cities[i] - cities[i + 1]);
      }
      int min = Math.min(left, right);

      left = Math.abs(cities[i] - cities[0]);
      right = Math.abs(cities[i] - cities[n - 1]);
      int max = Math.max(left, right);

      System.out.println(min + " " + max);
    }
  }
コード例 #5
0
ファイル: Solution.java プロジェクト: zzoeliu/leetcode_java
  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();
  }
コード例 #6
0
ファイル: WordHunt.java プロジェクト: kycwuwu/WordHunt
  /** 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.");
    }
  }
コード例 #7
0
  public static void main(String args[]) {

    Scanner in = new Scanner(System.in);

    int n = in.nextInt();
    int[] arr = new int[n];

    for (int i = 0; i < n; ++i) arr[i] = in.nextInt();

    int count = 0;
    for (int j = 1; j < n; ++j) {

      int key = arr[j];
      int i = j - 1;

      while (i >= 0 && arr[i] > key) {
        arr[i + 1] = arr[i];
        --i;
        ++count;
      }
      arr[i + 1] = key;
    }

    System.out.println(count);
  }
コード例 #8
0
  public static void main(String args[]) {

    if (args.length < 1 || args.length > 1) {
      System.out.println("Usage: TextGenMain [filename]");
      System.exit(1);
    }

    Scanner keyboard = new Scanner(System.in);
    int seedSize;

    System.out.print("Size of seed to use? (default is 2) ");
    seedSize = keyboard.nextInt();

    if (seedSize < 1) seedSize = 2;

    Markov mv = new Markov(seedSize);
    mv.initialize(args[0]);

    int sentences;
    String goAgain;

    do {
      do {
        System.out.print("Number of sentences to generate: ");
        sentences = keyboard.nextInt();
      } while (sentences < 1);
      mv.generateText(sentences);
      System.out.print("\nGo again? (Y/N) ");
      goAgain = keyboard.next();
    } while (goAgain.toUpperCase().charAt(0) == 'Y');

    System.out.println();
  } // end main
コード例 #9
0
ファイル: Main.java プロジェクト: mrain/acm
 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]);
   }
 }
コード例 #10
0
ファイル: 239.java プロジェクト: Zhi2014/AlgoSolution
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int n = in.nextInt();
   int[] a = new int[n];
   for (int i = 0; i < n; ++i) {
     a[i] = in.nextInt();
   }
   int ans = 0;
   boolean[] b = new boolean[n + 1];
   for (int k = 0; k <= 1; ++k) {
     boolean flag = true;
     int cnt = k;
     b[0] = (k == 1);
     for (int i = 0; flag && i < n; ++i) {
       if (cnt == a[i]) {
         b[i + 1] = false;
       } else if (cnt == a[i] - 1) {
         b[i + 1] = true;
         ++cnt;
       } else {
         flag = false;
       }
       if (i > 0 && b[i - 1]) {
         --cnt;
       }
     }
     if (flag && !b[n]) {
       ++ans;
     }
   }
   System.out.println(ans);
 }
コード例 #11
0
  public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    // prompt the user for the number of numbers
    System.out.print("How many integers (up to " + MAX_SIZE);
    System.out.print(") would you like to see? ");
    // get the number of numbers
    int size = input.nextInt();
    if (size > MAX_SIZE) size = MAX_SIZE;
    int[] numbers = new int[size]; // the list of integers
    // fill the list with 'size' random numbers.
    makeList(numbers);

    // display the numbers
    for (int i = 0; i < numbers.length; i++) System.out.println(numbers[i]);

    // prompt the user to hide the nubmers
    System.out.print("Type 1 when you are ready to hide the numbers: ");
    input.nextInt();
    // scroll the numbers off the terminal
    for (int i = 0; i < 50; i++) System.out.println();

    System.out.println("Score: " + numCorrect(numbers) + " correct out of " + size + " numbers.");
  }
コード例 #12
0
  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");
  }
コード例 #13
0
ファイル: BackupDP.java プロジェクト: wkoder/algorithms
 public static void main(String[] args) {
   final int INF = 1 << 30;
   Scanner scan = new Scanner(System.in);
   int N = scan.nextInt();
   int K = scan.nextInt();
   int[] d = new int[N + 1];
   for (int i = 0; i < N; i++) d[i + 1] = scan.nextInt();
   N++;
   for (int i = N - 1; i > 0; i--) d[i] -= d[i - 1];
   int[] prev = new int[N];
   int[] dp = new int[N];
   Arrays.fill(prev, INF);
   prev[0] = 0;
   for (int k = 0; k < K; k++) {
     int best = INF;
     for (int i = 0; i < N; i++) {
       if (i >= 2) best = Math.min(best, prev[i - 2]);
       dp[i] = INF;
       if (i > 0) {
         dp[i] = Math.min(dp[i], dp[i - 1] + d[i]);
         dp[i] = Math.min(dp[i], best + d[i]);
       }
     }
     int[] temp = prev;
     prev = dp;
     dp = temp;
   }
   int min = INF;
   for (int i = 0; i < N; i++) min = Math.min(min, prev[i]);
   System.out.println(min);
 }
コード例 #14
0
ファイル: Floyd.java プロジェクト: pranaliyawalkar/Codes
 public void process() {
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int m = sc.nextInt();
   int[][] dist = new int[n][n];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       if (i != j) dist[i][j] = 9999999;
     }
   }
   for (int i = 0; i < m; i++) {
     int a = sc.nextInt();
     int b = sc.nextInt();
     int c = sc.nextInt();
     a--;
     b--;
     dist[a][b] = c;
   }
   for (int k = 0; k < n; k++) {
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < n; j++) {
         if (dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k] + dist[k][j];
       }
     }
   }
   // dist[a][b] = shortest distance between them
 }
コード例 #15
0
ファイル: CheckNums.java プロジェクト: youjin9209/coderbyte
 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()));
 }
コード例 #16
0
  public static void main(String args[]) {

    Scanner in = new Scanner(System.in);

    int n = in.nextInt();

    String text = in.next();

    char[] input = new char[text.length()];

    int k = in.nextInt();

    for (int i = 0; i < text.length(); ++i) input[i] = text.charAt(i);

    for (int i = 0; i < text.length(); ++i) {
      if (Character.isLetter(input[i])) {

        int value = (int) input[i] + k % 26;

        if (Character.isLowerCase(input[i])) {

          if (value > (int) 'z') value = value - 26;

        } else if (Character.isUpperCase(input[i])) {
          if (value > (int) 'Z') value = value - 26;
        }

        input[i] = (char) value;
      }
    }

    for (int i = 0; i < n; ++i) System.out.print(input[i]);

    System.out.println();
  }
コード例 #17
0
ファイル: Ghosts.java プロジェクト: franko4don/programs
 /** @param args the command line arguments */
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   int C = sc.nextInt();
   int D = sc.nextInt();
   int count = 0;
   for (int i = 1; i <= A; i++) {
     for (int j = 1; j <= B; j++) {
       for (int k = 1; k <= C; k++) {
         for (int l = 1; l <= D; l++) {
           int case1 = Math.abs(i - j) % 3;
           int case2 = (j + k) % 5;
           int case3 = (i * k) % 4;
           int case4 = gcd(i, l);
           if (case1 == 0 && case2 == 0 && case3 == 0 && case4 == 1) {
             count++;
             System.out.println(i + " " + j + " " + k + " " + l);
           }
         }
       }
     }
   }
   System.out.println(count);
 }
コード例 #18
0
ファイル: TestClass.java プロジェクト: rituc/Programming
  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());
    }
  }
コード例 #19
0
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    for (; ; ) {
      int seqLen = input.nextInt();
      if (seqLen == 0) break;
      int[] sequence = new int[seqLen];
      for (int i = 0; i < seqLen; i++) {
        sequence[i] = input.nextInt();
      }

      ArrayList<Integer> experiment = new ArrayList<Integer>(seqLen);
      int current = 0;
      for (int i = 1; i <= seqLen; i++) {
        int numAdd = sequence[i - 1] - current;
        for (int j = 0; j < numAdd; j++) {
          experiment.add(i);
          current++;
        }
      }

      for (Integer i : experiment) {
        System.out.print(i + " ");
      }
      System.out.println();
    }
  }
コード例 #20
0
  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);
    }
  }
コード例 #21
0
ファイル: Main_Qihoo1.java プロジェクト: zzzbit/onlinejudge
  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");
      }
    }
  }
コード例 #22
0
 public static void main(String[] args) {
   Scanner input = new Scanner(System.in);
   int n = input.nextInt(), m = input.nextInt();
   int[] data = new int[m], data2 = new int[m];
   for (int i = 0; i < m; i++) {
     data[i] = input.nextInt();
     data2[i] = data[i];
   }
   Arrays.sort(data);
   Arrays.sort(data2);
   // find min
   int at = 0, min = 0, max = 0, needed = n;
   while (needed > 0) {
     min += data[at];
     data[at]--;
     needed--;
     if (data[at] == 0) at++;
   }
   needed = n;
   while (needed > 0) {
     needed--;
     max += data2[m - 1];
     data2[m - 1]--;
     Arrays.sort(data2);
   }
   System.out.println(max + " " + min);
 }
コード例 #23
0
  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);
        }
      }
    }
  }
コード例 #24
0
ファイル: UVA11385.java プロジェクト: petr-lee/UVaSolutions
 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]", "");
 }
コード例 #25
0
 public static void main(String args[]) {
   Scanner s1 = new Scanner(System.in);
   int len = s1.nextInt();
   int freq[] = new int[100001];
   int starts[] = new int[100001];
   int big = 0;
   int small = len + 1;
   int end = 0, size = 0, l = 0, r = 0;
   int curr;
   for (int i = 0; i < len; i++) {
     curr = s1.nextInt();
     if (freq[curr] == 0) {
       starts[curr] = i;
       freq[curr] = 1;
     } else {
       (freq[curr])++;
       end = i;
     }
     if (freq[curr] >= big) {
       big = freq[curr];
       size = (end) - starts[curr] + 1;
       if (size < small) {
         small = size;
         l = starts[curr] + 1;
         r = end + 1;
       }
     }
   }
   s1.close();
   System.out.print(l + " " + r);
 }
コード例 #26
0
 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");
   }
 }
コード例 #27
0
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int v = input.nextInt();
    boolean[] canBuy = new boolean[n];
    int canBuyCounter = 0;
    for (int i = 0; i < n; i++) {
      int n1 = input.nextInt();
      int[] prices = new int[n1];
      for (int j = 0; j < n1; j++) {
        prices[j] = input.nextInt();
      }
      for (int j : prices) {
        if (v > j) {
          canBuyCounter++;
          canBuy[i] = true;
          break;
        }
      }
    }

    System.out.println(canBuyCounter);
    boolean firstPrint = true;
    for (int i = 0; i < n; i++) {
      if (canBuy[i]) {
        if (firstPrint) {
          firstPrint = false;
        } else {
          System.out.print(" ");
        }
        System.out.print((i + 1));
      }
    }
    System.out.println();
  }
コード例 #28
0
 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);
 }
コード例 #29
0
ファイル: 1807.java プロジェクト: Whedoloca/ACM-ICPC
  public static void main(String args[]) {
    Scanner input = new Scanner(System.in);
    int T = input.nextInt();
    CPoint[] array = new CPoint[SIZE];
    for (int t = 0; t < T; t++) {
      int n = input.nextInt();
      for (int i = 0; i < n; i++) {
        int a = input.nextInt();
        int b = input.nextInt();
        array[i] = new CPoint();
        array[i].setPoint(a, b);
      }

      int ans = 0;
      for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++)
          if (i != j) {
            if (array[j].x > array[i].x && array[j].y > array[i].y) sum++;
            if (array[j].x < array[i].x && array[j].y < array[i].y) sum++;
          }
        if (sum > ans) ans = sum;
      }
      System.out.println(ans);
    }
  }
コード例 #30
0
ファイル: Main.java プロジェクト: MrSaad/ACM-Problems
  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);
    }
  }