示例#1
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);
    }
  }
  public double getValue(double x) {
    Map.Entry<Double, Double> e1, e2;
    double x1, x2;
    double y1, y2;

    if (Double.isNaN(x)) return Double.NaN;

    e1 = sortMap.floorEntry(x);

    if (e1 == null) {
      // x smaller than any value in the set
      e1 = sortMap.firstEntry();
      if (e1 == null) {
        return Double.NaN;
      }
      e2 = sortMap.higherEntry(e1.getKey());
      if (e2 == null) {
        // only one value in the set
        return e1.getValue();
      }
    } else {

      e2 = sortMap.higherEntry(e1.getKey());
      if (e2 == null) {
        // x larger than any value in the set
        e2 = e1;
        e1 = sortMap.lowerEntry(e2.getKey());
        if (e1 == null) {
          // only one value in the set
          return e2.getValue();
        }
      }
    }

    x1 = e1.getKey();
    x2 = e2.getKey();
    y1 = e1.getValue();
    y2 = e2.getValue();

    return (x - x1) / (x2 - x1) * (y2 - y1) + y1;
  }
示例#3
0
 void compute() {
   NavigableMap<GregorianCalendar, run> briefName = scores.descendingMap();
   double differentials[] = new double[20];
   for (i = 0, iterator = scores.firstEntry(); i < 20; i++) {
     tmp = courses.get(iterator.getValue().course);
     differentials[i] = (iterator.getValue().score - tmp.rating) * 113.0 / tmp.slope;
     iterator = scores.higherEntry(iterator.getKey());
   }
   Arrays.sort(differentials);
   score = 0.0;
   for (i = 0; i < 10; i++) {
     score += differentials[i];
   }
   score /= 10;
 }
示例#4
0
  /**
   * Calculates estimated number of points in interval [-∞,b].
   *
   * @param b upper bound of a interval to calculate sum
   * @return estimated number of points in a interval [-∞,b].
   */
  public double sum(double b) {
    double sum = 0;
    // find the points pi, pnext which satisfy pi <= b < pnext
    Map.Entry<Double, Long> pnext = bin.higherEntry(b);
    if (pnext == null) {
      // if b is greater than any key in this histogram,
      // just count all appearance and return
      for (Long value : bin.values()) sum += value;
    } else {
      Map.Entry<Double, Long> pi = bin.floorEntry(b);
      if (pi == null) return 0;
      // calculate estimated count mb for point b
      double weight = (b - pi.getKey()) / (pnext.getKey() - pi.getKey());
      double mb = pi.getValue() + (pnext.getValue() - pi.getValue()) * weight;
      sum += (pi.getValue() + mb) * weight / 2;

      sum += pi.getValue() / 2.0;
      for (Long value : bin.headMap(pi.getKey(), false).values()) sum += value;
    }
    return sum;
  }
示例#5
0
 public Map.Entry<K, V> higherEntry(K key) {
   return realMap.higherEntry(key);
 }
示例#6
0
 /** Return the endpoint that has the lowest token greater than this ep's token */
 EndPoint getTokenAfter(EndPoint ep) {
   BigInteger token = endPointToTokenMap_.get(ep);
   Map.Entry<BigInteger, EndPoint> entry = tokenToEndPointMap_.higherEntry(token);
   if (entry != null) return entry.getValue();
   return tokenToEndPointMap_.firstEntry().getValue(); // wrap
 }