示例#1
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);
        }
      }
    }
  }
示例#2
0
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int n = in.nextInt();
   int[] data = new int[n];
   for (int i = 0; i < n; i++) data[i] = -1;
   for (int i = 0; i < n; i++) {
     in.next();
     if (in.nextInt() == 1) {
       data[i] = in.nextInt();
     }
   }
   int max = 10000;
   int max_sum = 0;
   int min_sum = 0;
   int cnt = 0;
   for (int i = 0; i < n; i++) {
     if (data[i] == -1) {
       max_sum += max;
       cnt++;
     } else {
       max = data[i];
       max_sum += data[i];
       min_sum += (cnt + 1) * data[i];
       cnt = 0;
     }
   }
   min_sum += cnt;
   // System.out.println(min_sum+" "+max_sum);
   if (min_sum <= 100 * 100 && max_sum >= 100 * 100) System.out.println("YES");
   else System.out.println("NO");
 }
示例#3
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("");
    }
  }
示例#4
0
  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);
    }
  }
示例#5
0
文件: 433.java 项目: jmankhan/ACM
  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);
  }
  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) {

    }
  }
示例#7
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);
    }
  }
示例#8
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]);
   }
 }
示例#9
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 cases = in.nextInt();
   for (int i = 0; i < cases; i++) {
     System.out.println(digits(in.nextInt()));
   }
 }
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int t = in.nextInt();
   for (int a0 = 0; a0 < t; a0++) {
     int n = in.nextInt();
     int treeHeight = getHeightOfTree(n);
     System.out.println(treeHeight);
   }
 }
 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 numberOfTestCases = in.nextInt();
   for (int i = 0; i < numberOfTestCases; i++) {
     int n = in.nextInt();
     System.out.println((n * (n - 1)) / 2);
   }
 }
示例#12
0
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int n = in.nextInt();
   int k = in.nextInt();
   int arr[] = new int[n];
   for (int i = 0; i < n; i++) {
     arr[i] = in.nextInt();
   }
   System.out.println("Ans: " + findK(arr, 0, n - 1, k));
 }
示例#13
0
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int k = sc.nextInt();
   while (k > 0) {
     int a = sc.nextInt();
     int b = sc.nextInt();
     int n = sc.nextInt();
     printer(a, b, n);
     k--;
   }
 }
示例#14
0
  public static void main(String[] args) {
    BigInteger sum = BigInteger.ZERO;
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int arr[] = new int[n];
    for (int arr_i = 0; arr_i < n; arr_i++) {
      arr[arr_i] = in.nextInt();

      sum = sum.add(BigInteger.valueOf(arr[arr_i]));
    }
    System.out.println(sum);
  }
示例#15
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();
    }

    for (int i = N - 1; i >= 0; i--) {
      System.out.print(arr[i] + " ");
    }
  }
示例#16
0
  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int width = in.nextInt(); // the number of cells on the X axis
    in.nextLine();
    int height = in.nextInt(); // the number of cells on the Y axis
    in.nextLine();

    boolean[][] nodes = new boolean[height][width];

    // Fill array
    for (int i = 0; i < height; i++) {
      String line = in.nextLine(); // width characters, each either 0 or .
      CharSequence cs = line;

      for (int j = 0; j < cs.length(); j++) {
        nodes[i][j] = (cs.charAt(j) == '0');
      }
    }

    // Find neighbors
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        int x1 = -1, y1 = -1;
        int x2 = -1, y2 = -1;
        int x3 = -1, y3 = -1;

        if (nodes[i][j]) {
          x1 = j;
          y1 = i;

          int nextJ = j;
          while (++nextJ < width && x2 == -1) {
            if (nodes[i][nextJ]) {
              x2 = nextJ;
              y2 = i;
            }
          }

          int nextI = i;
          while (++nextI < height && y3 == -1) {
            if (nodes[nextI][j]) {
              x3 = j;
              y3 = nextI;
            }
          }

          System.out.println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3);
        }
      }
    }
  }
示例#17
0
  public static void main(String args[]) {

    int NUM_LETTERS = 27;
    char[] alfabet = {
      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
      'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '?'
    };

    Scanner in = new Scanner(System.in);
    int L = in.nextInt();
    in.nextLine();
    int H = in.nextInt();
    in.nextLine();
    // to store the letter in asci artM
    char[][] art = new char[H][L * NUM_LETTERS];
    String T = in.nextLine(); // text to translate

    System.err.println("create array L:" + L + "/H:" + H + "/to translate:" + T);

    // saving asci art
    for (int i = 0; i < H; i++) {
      String ROW = in.nextLine(); // first line of all letters in asci art
      // the ROW must be saved in L chars groups
      // System.err.println("readed->" + ROW);
      char[] aux = ROW.toCharArray();
      for (int j = 0; j < aux.length; j++) {
        // System.err.println("guardando->["+i+"]["+j+"]" + aux[j]);
        art[i][j] = aux[j];
      }
    }

    StringBuilder builder = new StringBuilder();
    char[] translation = T.toCharArray();
    for (int m = 0; m < H; m++) {
      StringBuilder linea = new StringBuilder();
      for (int j = 0; j < translation.length; j++) {
        // neet to get char -> letter number to get position
        int position = returnPosition(Character.toUpperCase(translation[j]), alfabet);

        int start = (position * L);
        for (int u = start; u < (start + L); u++) {
          linea.append(art[m][u]);
        }
      }
      System.out.println(linea);
    }

    // Write an action using System.out.println()
    // To debug: System.err.println("Debug messages...");

  }
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    Scanner input = new Scanner(System.in);
    int numberOfTestCases = input.nextInt();
    ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases);
    int previousKey = -1;
    int previousValue = 0;
    int cycleNumber = 0;

    Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>();

    for (int i = 0; i < numberOfTestCases; i++) {
      int numberOfCycles = input.nextInt();
      testCases.put(numberOfCycles, 1);
      order.add(numberOfCycles);
    }

    for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) {
      int numberOfCycles;
      int initialHeight;

      if (previousKey == -1) {
        numberOfCycles = entry.getKey();
        initialHeight = entry.getValue();
      } else {
        numberOfCycles = entry.getKey() - previousKey;
        initialHeight = previousValue;
      }

      for (int i = 0; i < numberOfCycles; i++) {
        if (cycleNumber % 2 == 0) {
          initialHeight *= 2;
        } else {
          initialHeight += 1;
        }
        cycleNumber++;
      }

      entry.setValue(initialHeight);
      previousKey = entry.getKey();
      previousValue = initialHeight;
    }

    for (Integer element : order) {
      System.out.println(testCases.get(element));
    }

    long elapsed = System.currentTimeMillis() - start;
    System.out.println("time: " + elapsed);
  }
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int T;
   T = in.nextInt();
   while ((T--) > 0) {
     int n = in.nextInt(), k = in.nextInt();
     int value[] = new int[n];
     for (int i = 0; i < n; i++) {
       value[i] = in.nextInt();
     }
     System.out.println(UKS(value, n, k));
   }
   in.close();
 }
示例#20
0
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }

    Difference D = new Difference(a);

    D.computeDifference();

    System.out.print(D.maximumDifference);
  }
示例#21
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int k = in.nextInt();
    int a[] = new int[n];
    for (int a_i = 0; a_i < n; a_i++) {
      a[a_i] = in.nextInt();
    }

    int[] output = new int[n];
    output = arrayLeftRotation(a, n, k);
    for (int i = 0; i < n; i++) System.out.print(output[i] + " ");

    System.out.println();
  }
 public Solution() {
   Scanner scan = new Scanner(System.in);
   n = scan.nextInt();
   m = scan.nextInt();
   roads = new ArrayList<Road>[n];
   for (int i = 0; i < n; i++) {
     roads[i] = new ArrayList<Road>();
   }
   for (int i = 0; i < m; i++) {
     int start = scan.nextInt() - 1;
     int end = scan.nextInt() - 1;
     int condition = scan.nextInt();
     roads[start].add(new Road(end, condition == 1));
   }
 }
示例#23
0
文件: b.java 项目: ysyshtc/Codeforces
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
    disjoint = new int[n];
    for (int i = 0; i < n; ++i) disjoint[i] = i;

    for (int i = 0; i <= n - k; ++i) for (int j = 0; j < k; ++j) merge(i + j, i + k - 1 - j);

    long ret = 1;
    for (int i = 0; i < n; ++i) if (disjoint[i] == i) ret = ret * m % MD;
    out.println(ret);
    out.close();
  }
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
 public static void main(String[] args) {
   Scanner inp = new Scanner(System.in);
   int n = inp.nextInt();
   String[] store = new String[n];
   for (int i = 0; i < n; i++) store[i] = inp.next();
   int[] cnt = new int[n];
   Arrays.fill(cnt, 0);
   String str = inp.next();
   for (int j = 0; j < n; j++) {
     int l1 = store[j].length();
     for (int k = 0; k <= (str.length() - l1); k++) {
       if (str.substring(k, k + l1).equals(store[j])) {
         cnt[j] = cnt[j] + 1;
       }
     }
   }
   int y = 0;
   for (int m = 0; m < n; m++) {
     y = Math.max(y, cnt[m]);
   }
   System.out.println(y);
   for (int h = 0; h < n; h++) {
     if (cnt[h] == y) System.out.println(store[h]);
   }
 }
示例#26
0
 public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   int n = s.nextInt();
   int m = s.nextInt();
   int[][] b = new int[n][m];
   for (int i = 0; i < n; i++) {
     String line = s.next();
     for (int j = 0; j < m; j++) {
       b[i][j] = line.charAt(j) - '0';
     }
   }
   int[][] a = new int[n][m];
   for (int i = 0; i < n - 2; i++) {
     for (int j = 1; j < m - 1; j++) {
       if (b[i][j] > 0) {
         a[i + 1][j] = b[i][j];
         b[i][j] -= a[i + 1][j];
         b[i + 1][j - 1] -= a[i + 1][j];
         b[i + 1][j + 1] -= a[i + 1][j];
         b[i + 2][j] -= a[i + 1][j];
       }
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       System.out.print(a[i][j]);
     }
     System.out.println();
   }
 }
  public void init() {
    Scanner scan = new Scanner(System.in);
    n = scan.nextInt();
    m = scan.nextInt();
    for (int i = 0; i < n; i++) {
      String input = scan.next();
      record.add(input);
    }

    for (int i = 0; i < m; i++) {
      String input = scan.next();
      char[] charArray = input.toCharArray();
      boolean isValid = false;
      for (int j = 0; j < charArray.length; j++) {
        char c = charArray[j];
        for (char d = 'a'; d <= 'c'; d = (char) (d + 1)) {
          if (d == c) continue;
          charArray[j] = d;
          if (record.contains(new String(charArray))) {
            isValid = true;
            break;
          }
        }
        charArray[j] = c;
        if (isValid) break;
      }
      if (isValid) System.out.println("YES");
      else System.out.println("NO");
    }
    scan.close();
  }
示例#28
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int arr[][] = new int[6][6];
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        arr[i][j] = in.nextInt();
      }
    }

    List sum = new ArrayList();
    for (int i = 1; i < 5; i++) {
      for (int j = 1; j < 5; j++) {
        int temp =
            arr[i][j]
                + arr[i - 1][j - 1]
                + arr[i - 1][j]
                + arr[i - 1][j + 1]
                + arr[i + 1][j - 1]
                + arr[i + 1][j]
                + arr[i + 1][j + 1];
        sum.add(temp);
      }
    }

    System.out.println(Collections.max(sum));
  }
示例#29
0
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int t = in.nextInt();
   for (int a0 = 0; a0 < t; a0++) {
     int n = in.nextInt();
     int k = in.nextInt();
     int c = 0;
     int a[] = new int[n];
     for (int a_i = 0; a_i < n; a_i++) {
       a[a_i] = in.nextInt();
       if (a[a_i] <= 0) c++;
     }
     if (c < k) System.out.println("YES");
     else System.out.println("NO");
   }
 }
示例#30
0
文件: Shuoj1141.java 项目: yahaa/Java
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println(3 ^ 5 ^ 4 ^ 5 ^ 5 ^ 6 ^ 6 ^ 7);
    System.out.println(3 ^ 7);

    int[] a = new int[10];
    for (int i = 0; i < 10; i++) a[i] = input.nextInt();
    for (int aa : a) {
      System.out.print(aa);
    }
    sss(1, 3, 4, 5, 6, 7, 8, 9);

    BigInteger aa =
        new BigInteger(
            "12809348038290834905895869048359034859083495894038590438590348590834905890345");
    BigInteger bb = new BigInteger("111111111111111111111");
    System.out.println(aa.subtract(bb));
    BigDecimal rrrr = new BigDecimal(input.next());
    int aaa;
    double b;
    float c;
    StringBuilder sssss = new StringBuilder("1234234");
    System.out.println();

    Integer ttt = 4;
    Double t1 = 14.2;
  }