public void setSwingDataCollection(Collection<ICFSecurityISOCountryObj> value) {
   final String S_ProcName = "setSwingDataCollection";
   swingDataCollection = value;
   if (swingDataCollection == null) {
     arrayOfISOCountry = new ICFSecurityISOCountryObj[0];
   } else {
     int len = value.size();
     arrayOfISOCountry = new ICFSecurityISOCountryObj[len];
     Iterator<ICFSecurityISOCountryObj> iter = swingDataCollection.iterator();
     int idx = 0;
     while (iter.hasNext() && (idx < len)) {
       arrayOfISOCountry[idx++] = iter.next();
     }
     if (idx < len) {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(),
               S_ProcName,
               "Collection iterator did not fully populate the array copy");
     }
     if (iter.hasNext()) {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(),
               S_ProcName,
               "Collection iterator had left over items when done populating array copy");
     }
     Arrays.sort(arrayOfISOCountry, compareISOCountryByQualName);
   }
   PickerTableModel tblDataModel = getDataModel();
   if (tblDataModel != null) {
     tblDataModel.fireTableDataChanged();
   }
 }
Exemplo n.º 2
1
 static List<Answer> solve(int[] numbers) {
   int n = numbers.length;
   Element[] a = new Element[n];
   for (int i = 0; i < n; i++) {
     a[i] = new Element(numbers[i], i);
   }
   int id = -1;
   for (int i = 0; i < n; i++) {
     if (luckies.contains(a[i].x)) {
       id = i;
       break;
     }
   }
   Element[] b = a.clone();
   Arrays.sort(b);
   if (Arrays.equals(a, b)) {
     return new ArrayList<Answer>();
   }
   if (id == -1) {
     return null;
   }
   boolean[] did = new boolean[n];
   for (int i = 0; i < n; i++) {
     if (a[i] == b[i]) {
       did[i] = true;
     }
   }
   List<Answer> ans = new ArrayList<Answer>();
   int cur = 0;
   while (cur < n) {
     while (b[id] != a[id]) {
       int newId = b[id].n;
       swap(id, b[id].n, ans, a);
       did[id] = true;
       id = newId;
     }
     while (cur < n && did[cur] || cur == id) {
       cur++;
     }
     if (cur < n) {
       int newId = cur;
       swap(cur, id, ans, a);
       id = newId;
     }
   }
   // for (int i = 1; i < n; i++) {
   // if (a[i].x < a[i - 1].x) {
   // throw new AssertionError();
   // }
   // }
   // if (ans.size() > 2 * n) {
   // throw new AssertionError();
   // }
   return ans;
 }
Exemplo n.º 3
0
 public int count(
     String[] s1000,
     String[] s100,
     String[] s10,
     String[] s1,
     String[] t1000,
     String[] t100,
     String[] t10,
     String[] t1) {
   String S1000 = concate(s1000);
   String S100 = concate(s100);
   String S10 = concate(s10);
   String S1 = concate(s1);
   String T1000 = concate(t1000);
   String T100 = concate(t100);
   String T10 = concate(t10);
   String T1 = concate(t1);
   int n = S1000.length();
   Interval[] intervals = new Interval[n];
   for (int i = 0; i < n; ++i) {
     intervals[i] =
         new Interval(
             Integer.parseInt(
                 S1000.substring(i, i + 1) + S100.charAt(i) + S10.charAt(i) + S1.charAt(i)),
             Integer.parseInt(
                 T1000.substring(i, i + 1) + T100.charAt(i) + T10.charAt(i) + T1.charAt(i)));
   }
   Arrays.sort(intervals);
   int leftmost = Integer.MAX_VALUE;
   int rightmost = Integer.MIN_VALUE;
   for (int i = 0; i < n; ++i) {
     leftmost = Math.min(leftmost, intervals[i].b);
     rightmost = Math.max(rightmost, intervals[i].a);
   }
   int answer = 0;
   for (int i = 0; i < n; ++i) {
     int total = 0;
     int now = leftmost;
     int j = 0;
     while (true) {
       if (intervals[i].a <= now) {
         now = Math.max(now, intervals[i].b);
       }
       if (now >= rightmost) {
         break;
       }
       int best = now;
       while (j < n && intervals[j].a <= now) {
         best = Math.max(best, intervals[j++].b);
       }
       if (best <= now) {
         return -1;
       }
       total++;
       now = best;
     }
     answer += total;
   }
   return answer;
 }
 public void loadData(boolean forceReload) {
   ICFFreeSwitchSchemaObj schemaObj = swingSchema.getSchema();
   if ((containingCluster == null) || forceReload) {
     CFSecurityAuthorization auth = schemaObj.getAuthorization();
     long containingClusterId = auth.getSecClusterId();
     containingCluster = schemaObj.getClusterTableObj().readClusterByIdIdx(containingClusterId);
   }
   if ((listOfTenant == null) || forceReload) {
     arrayOfTenant = null;
     listOfTenant =
         schemaObj
             .getTenantTableObj()
             .readTenantByClusterIdx(containingCluster.getRequiredId(), swingIsInitializing);
     if (listOfTenant != null) {
       Object objArray[] = listOfTenant.toArray();
       if (objArray != null) {
         int len = objArray.length;
         arrayOfTenant = new ICFSecurityTenantObj[len];
         for (int i = 0; i < len; i++) {
           arrayOfTenant[i] = (ICFSecurityTenantObj) objArray[i];
         }
         Arrays.sort(arrayOfTenant, compareTenantByQualName);
       }
     }
   }
 }
 public List<ICFAccTaxObj> readAllTax(boolean forceRead) {
   final String S_ProcName = "readAllTax";
   if ((allTax == null) || forceRead) {
     Map<CFAccTaxPKey, ICFAccTaxObj> map = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     allTax = map;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readAllDerived(schema.getAuthorization());
     CFAccTaxBuff buff;
     ICFAccTaxObj obj;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = allTax.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> valIter = allTax.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }
Exemplo n.º 6
0
 private long[] parse(String[] as) {
   long ans[] = new long[as.length];
   int index = 0;
   for (String cur : as) ans[index++] = Long.parseLong(cur, 2);
   Arrays.sort(ans);
   return ans;
 }
 private static void sort(long[] l1) {
   for (int i = 0; i < l1.length; i++) {
     int q = i + usingRandomGenerator.nextInt(l1.length - i);
     long t = l1[i];
     l1[i] = l1[q];
     l1[q] = t;
   }
   Arrays.sort(l1);
 }
Exemplo n.º 8
0
 public int maxCities(int total, int[] d) {
   Arrays.sort(d);
   int n = d.length;
   int answer = 0;
   while (answer < n && total >= d[answer]) {
     total -= d[answer++];
   }
   return answer;
 }
Exemplo n.º 9
0
 void solve(int caseNum) {
   int n = in.nextInt();
   BigInteger[] past = new BigInteger[n], d = new BigInteger[n];
   for (int i = 0; i < n; i++) past[i] = new BigInteger(in.next());
   Arrays.sort(past);
   for (int i = 0; i < n; i++) d[i] = past[i].subtract(past[0]);
   for (int i = 2; i < n; i++) d[i] = d[i].gcd(d[i - 1]);
   BigInteger gcd = d[n - 1], mod = past[0].mod(gcd);
   System.out.printf("Case #%d: ", caseNum);
   if (mod.equals(BigInteger.ZERO)) System.out.println(0);
   else System.out.println(gcd.subtract(mod));
 }
Exemplo n.º 10
0
 public static void process() {
   Arrays.sort(bookHeight);
   BigInteger sum = BigInteger.valueOf(0L);
   BigInteger temp;
   int iCount = 0;
   for (int i = bookHeight.length - 1; i >= 0; i--) {
     sum = sum.add(BigInteger.valueOf((long) (bookHeight[i])));
     temp = sum.max(b);
     iCount++;
     if (temp.equals(sum)) break;
   }
   System.out.print(iCount);
 }
Exemplo n.º 11
0
 static boolean next_permutation(int[] perm) {
   int n = perm.length;
   int inc = -1;
   for (int i = 0; i < n - 1; i++) if (perm[i] < perm[i + 1]) inc = i;
   if (inc != -1) {
     int inc_val = perm[inc];
     perm[inc] = Integer.MAX_VALUE;
     int min_ptr = inc;
     for (int i = inc + 1; i < n; i++)
       if (perm[i] < perm[min_ptr] && perm[i] > inc_val) min_ptr = i;
     if (min_ptr == -1) min_ptr = inc;
     perm[inc] = perm[min_ptr];
     perm[min_ptr] = inc_val;
   }
   Arrays.sort(perm, inc + 1, n);
   return inc == -1 ? false : true;
 }
Exemplo n.º 12
0
  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int C = in.nextInt();
    // System.err.println("N " + N + " C " + C);
    int[] contribsMax = new int[N];
    int somme = 0;
    for (int i = 0; i < N; i++) {
      int B = in.nextInt();
      contribsMax[i] = B;
      // System.err.println("contrib " + i + " : " + B);
      somme += B;
    }

    // Write an action using System.out.println()
    // To debug: System.err.println("Debug messages...");
    if (somme < C) {
      System.out.println("IMPOSSIBLE");
    } else {
      int remaining = C;
      int guy = 0;

      Arrays.sort(contribsMax);

      do {
        int remainingGuys = N - guy;
        int contribMeanRemaining = remaining / remainingGuys;
        // System.err.println("remaining mean " + contribMeanRemaining);

        int currentContrib = contribsMax[guy];
        // System.err.println("current contrib " + currentContrib);

        if (contribMeanRemaining < currentContrib) {
          System.out.println(contribMeanRemaining);
        } else {
          contribMeanRemaining = currentContrib;
          System.out.println(currentContrib);
        }

        remaining -= contribMeanRemaining;
        guy++;
      } while (guy < N);
    }
  }
 public void loadData(boolean forceReload) {
   ICFSecuritySchemaObj schemaObj = swingSchema.getSchema();
   if ((listOfISOTimezone == null) || forceReload) {
     arrayOfISOTimezone = null;
     listOfISOTimezone =
         schemaObj.getISOTimezoneTableObj().readAllISOTimezone(swingIsInitializing);
     if (listOfISOTimezone != null) {
       Object objArray[] = listOfISOTimezone.toArray();
       if (objArray != null) {
         int len = objArray.length;
         arrayOfISOTimezone = new ICFSecurityISOTimezoneObj[len];
         for (int i = 0; i < len; i++) {
           arrayOfISOTimezone[i] = (ICFSecurityISOTimezoneObj) objArray[i];
         }
         Arrays.sort(arrayOfISOTimezone, compareISOTimezoneByQualName);
       }
     }
   }
 }
 public void loadData(boolean forceReload) {
   ICFBamSchemaObj schemaObj = swingSchema.getSchema();
   if ((listOfAccessFrequency == null) || forceReload) {
     arrayOfAccessFrequency = null;
     listOfAccessFrequency =
         schemaObj.getAccessFrequencyTableObj().readAllAccessFrequency(swingIsInitializing);
     if (listOfAccessFrequency != null) {
       Object objArray[] = listOfAccessFrequency.toArray();
       if (objArray != null) {
         int len = objArray.length;
         arrayOfAccessFrequency = new ICFBamAccessFrequencyObj[len];
         for (int i = 0; i < len; i++) {
           arrayOfAccessFrequency[i] = (ICFBamAccessFrequencyObj) objArray[i];
         }
         Arrays.sort(arrayOfAccessFrequency, compareAccessFrequencyByQualName);
       }
     }
   }
 }
Exemplo n.º 15
0
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        T = sc.nextInt();
        for (int _ = 0; _ < T; _++) {
            n = sc.nextInt();
            a = sc.next();
            scs = new BigInteger[n];
            for (int i = 0; i < n; i++) {
                scs[i] = BigInteger.ZERO;
            }
            int ix = 0, cur = 0;
            while (ix < a.length()) {
                ix = turn(cur, ix);
                cur = (cur + 1) % n;
            }
//            System.out.println(n + ": " + a);
//            for (int i = 0; i < n; i++) System.out.println(scs[i]);
            Arrays.sort(scs);
            System.out.println(scs[n-1]);
        }
    }
Exemplo n.º 16
0
 double solve(Point[] points) {
   int n = points.length;
   Arrays.sort(points);
   Point[] down = getConvex(points);
   Point[] up = reverse(getConvex(reverse(points)));
   int xMin = down[0].x;
   int xMax = down[down.length - 1].x;
   long total = 0;
   double sum = 0.0;
   double squareSum = 0.0;
   for (int x = xMin, i = 0, j = 0; x <= xMax; ++x) {
     while (i + 1 < down.length && down[i + 1].x < x) {
       i++;
     }
     while (j + 1 < up.length && up[j + 1].x < x) {
       j++;
     }
     int yMin =
         (int)
                 Math.ceil(
                     (double) (x - down[i].x)
                         / (down[i + 1].x - down[i].x)
                         * (down[i + 1].y - down[i].y))
             + down[i].y;
     int yMax =
         (int)
                 Math.floor(
                     (double) (x - up[j].x) / (up[j + 1].x - up[j].x) * (up[j + 1].y - up[j].y))
             + up[j].y;
     int count = yMax - yMin + 1;
     total += count;
     sum += (double) count * x;
     squareSum += (double) count * x * x;
   }
   return (total * squareSum - sum * sum) / ((double) total * (total - 1));
 }
 public List<ICFAccTaxObj> readTaxByTenantIdx(long TenantId, boolean forceRead) {
   final String S_ProcName = "readTaxByTenantIdx";
   CFAccTaxByTenantIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
   key.setRequiredTenantId(TenantId);
   Map<CFAccTaxPKey, ICFAccTaxObj> dict;
   if (indexByTenantIdx == null) {
     indexByTenantIdx = new HashMap<CFAccTaxByTenantIdxKey, Map<CFAccTaxPKey, ICFAccTaxObj>>();
   }
   if ((!forceRead) && indexByTenantIdx.containsKey(key)) {
     dict = indexByTenantIdx.get(key);
   } else {
     dict = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     // Allow other threads to dirty-read while we're loading
     indexByTenantIdx.put(key, dict);
     ICFAccTaxObj obj;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readDerivedByTenantIdx(schema.getAuthorization(), TenantId);
     CFAccTaxBuff buff;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = schema.getTaxTableObj().newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = dict.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> valIter = dict.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }