Пример #1
0
  public static void testICDE() {
    // Number of total operations
    int numberOfTests = 5;
    // Length of the p, note that n=p.q
    int lengthp = 512;

    Paillier esystem = new Paillier();
    Random rd = new Random();
    PaillierPrivateKey key = KeyGen.PaillierKey(lengthp, 122333356);
    esystem.setDecryptEncrypt(key);
    // let's test our algorithm by encrypting and decrypting few instances

    long start = System.currentTimeMillis();
    for (int i = 0; i < numberOfTests; i++) {
      BigInteger m1 = BigInteger.valueOf(Math.abs(rd.nextLong()));
      BigInteger m2 = BigInteger.valueOf(Math.abs(rd.nextLong()));
      BigInteger c1 = esystem.encrypt(m1);
      BigInteger c2 = esystem.encrypt(m2);
      BigInteger c3 = esystem.multiply(c1, m2);
      c1 = esystem.add(c1, c2);
      c1 = esystem.add(c1, c3);

      esystem.decrypt(c1);
    }
    long stop = System.currentTimeMillis();
    System.out.println(
        "Running time per comparison in milliseconds: " + ((stop - start) / numberOfTests));
  }
 // BEGIN KAWIGIEDIT TESTING
 // Generated by KawigiEdit-pf 2.3.0
 private static boolean KawigiEdit_RunTest(int testNum, int p0, boolean hasAnswer, int p1) {
   System.out.print("Test " + testNum + ": [" + p0);
   System.out.println("]");
   EmoticonsDiv1 obj;
   int answer;
   obj = new EmoticonsDiv1();
   long startTime = System.currentTimeMillis();
   answer = obj.printSmiles(p0);
   long endTime = System.currentTimeMillis();
   boolean res;
   res = true;
   System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
   if (hasAnswer) {
     System.out.println("Desired answer:");
     System.out.println("\t" + p1);
   }
   System.out.println("Your answer:");
   System.out.println("\t" + answer);
   if (hasAnswer) {
     res = answer == p1;
   }
   if (!res) {
     System.out.println("DOESN'T MATCH!!!!");
   } else if ((endTime - startTime) / 1000.0 >= 2) {
     System.out.println("FAIL the timeout");
     res = false;
   } else if (hasAnswer) {
     System.out.println("Match :-)");
   } else {
     System.out.println("OK, but is it right?");
   }
   System.out.println("");
   return res;
 }
Пример #3
0
  void solve(InputReader in) {

    try {

      long start = System.currentTimeMillis();

      F[0] = BigInteger.ONE;
      for (i = 1; i <= 30; ++i) F[i] = F[i - 1].multiply(BigInteger.valueOf(i));

      for (i = 1; i <= 30; ++i) {
        for (j = 1; j <= i; ++j) {
          C[i][j] = getResult(i, j);
        }
      }

      t = in.nextInt();
      while (t-- > 0) {
        for (i = 1; i <= 30; ++i) g[i] = new ArrayList();
        n = in.nextInt();
        for (i = 1; i <= n; ++i) a[i] = in.nextInt();
        root = a[1];
        p = 2;
        Construct(root, 1, 30);
        Pair ans = Calculate(root);
        System.out.println(ans.x);
      }

      long end = System.currentTimeMillis();
      if (time) System.out.println("Execution time: " + (double) (end - start) / 1000.0);
    } catch (Exception e) {
      System.out.println("Error: " + e);
    }
    ;
  }
 // BEGIN KAWIGIEDIT TESTING
 // Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
 private static boolean KawigiEdit_RunTest(
     int testNum, int p0, int p1, boolean hasAnswer, String p2) {
   System.out.print("Test " + testNum + ": [" + p0 + "," + p1);
   System.out.println("]");
   KLastNonZeroDigits obj;
   String answer;
   obj = new KLastNonZeroDigits();
   long startTime = System.currentTimeMillis();
   answer = obj.getKDigits(p0, p1);
   long endTime = System.currentTimeMillis();
   boolean res;
   res = true;
   System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
   if (hasAnswer) {
     System.out.println("Desired answer:");
     System.out.println("\t" + "\"" + p2 + "\"");
   }
   System.out.println("Your answer:");
   System.out.println("\t" + "\"" + answer + "\"");
   if (hasAnswer) {
     res = answer.equals(p2);
   }
   if (!res) {
     System.out.println("DOESN'T MATCH!!!!");
   } else if ((endTime - startTime) / 1000.0 >= 2) {
     System.out.println("FAIL the timeout");
     res = false;
   } else if (hasAnswer) {
     System.out.println("Match :-)");
   } else {
     System.out.println("OK, but is it right?");
   }
   System.out.println("");
   return res;
 }
 // BEGIN KAWIGIEDIT TESTING
 // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
 private static boolean KawigiEdit_RunTest(
     int testNum, int[] p0, int[] p1, int[] p2, boolean hasAnswer, int p3) {
   System.out.print("Test " + testNum + ": [" + "{");
   for (int i = 0; p0.length > i; ++i) {
     if (i > 0) {
       System.out.print(",");
     }
     System.out.print(p0[i]);
   }
   System.out.print("}" + "," + "{");
   for (int i = 0; p1.length > i; ++i) {
     if (i > 0) {
       System.out.print(",");
     }
     System.out.print(p1[i]);
   }
   System.out.print("}" + "," + "{");
   for (int i = 0; p2.length > i; ++i) {
     if (i > 0) {
       System.out.print(",");
     }
     System.out.print(p2[i]);
   }
   System.out.print("}");
   System.out.println("]");
   KeyDungeonDiv2 obj;
   int answer;
   obj = new KeyDungeonDiv2();
   long startTime = System.currentTimeMillis();
   answer = obj.countDoors(p0, p1, p2);
   long endTime = System.currentTimeMillis();
   boolean res;
   res = true;
   System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
   if (hasAnswer) {
     System.out.println("Desired answer:");
     System.out.println("\t" + p3);
   }
   System.out.println("Your answer:");
   System.out.println("\t" + answer);
   if (hasAnswer) {
     res = answer == p3;
   }
   if (!res) {
     System.out.println("DOESN'T MATCH!!!!");
   } else if ((endTime - startTime) / 1000.0 >= 2) {
     System.out.println("FAIL the timeout");
     res = false;
   } else if (hasAnswer) {
     System.out.println("Match :-)");
   } else {
     System.out.println("OK, but is it right?");
   }
   System.out.println("");
   return res;
 }
Пример #6
0
  public static void main(String[] args) {
    long start = System.currentTimeMillis();

    while (in.hasNext()) solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    in.close();
    out.close();
  }
Пример #7
0
  public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    br.close();
    out.close();
  }
Пример #8
0
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    dump((end - start) + "ms");
    in.close();
    out.close();
  }
Пример #9
0
  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);
  }
 // BEGIN KAWIGIEDIT TESTING
 // Generated by KawigiEdit-pf 2.3.0
 private static boolean KawigiEdit_RunTest(
     int testNum, int[] p0, int[] p1, boolean hasAnswer, double p2) {
   System.out.print("Test " + testNum + ": [" + "{");
   for (int i = 0; p0.length > i; ++i) {
     if (i > 0) {
       System.out.print(",");
     }
     System.out.print(p0[i]);
   }
   System.out.print("}" + "," + "{");
   for (int i = 0; p1.length > i; ++i) {
     if (i > 0) {
       System.out.print(",");
     }
     System.out.print(p1[i]);
   }
   System.out.print("}");
   System.out.println("]");
   GreaterGame obj;
   double answer;
   obj = new GreaterGame();
   long startTime = System.currentTimeMillis();
   answer = obj.calc(p0, p1);
   long endTime = System.currentTimeMillis();
   boolean res;
   res = true;
   System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
   if (hasAnswer) {
     System.out.println("Desired answer:");
     System.out.println("\t" + p2);
   }
   System.out.println("Your answer:");
   System.out.println("\t" + answer);
   if (hasAnswer) {
     res = answer == answer && Math.abs(p2 - answer) <= 1e-9 * Math.max(1.0, Math.abs(p2));
   }
   if (!res) {
     System.out.println("DOESN'T MATCH!!!!");
   } else if ((endTime - startTime) / 1000.0 >= 2) {
     System.out.println("FAIL the timeout");
     res = false;
   } else if (hasAnswer) {
     System.out.println("Match :-)");
   } else {
     System.out.println("OK, but is it right?");
   }
   System.out.println("");
   return res;
 }
Пример #11
0
 /**
  * Set Measure Actual
  *
  * @param MeasureActual actual
  */
 @Override
 public void setMeasureActual(BigDecimal MeasureActual) {
   if (MeasureActual == null) return;
   super.setMeasureActual(MeasureActual);
   setDateLastRun(new Timestamp(System.currentTimeMillis()));
   setGoalPerformance();
 } //	setMeasureActual
Пример #12
0
 public static void main(String[] args) throws IOException {
   //		in = new BufferedReader(new InputStreamReader(System.in));
   //		out = new PrintWriter(new BufferedOutputStream(System.out));
   String file = "C-large";
   in = new BufferedReader(new FileReader(file + ".in"));
   out = new PrintWriter(new FileOutputStream(file + "_" + System.currentTimeMillis() + ".out"));
   solve();
   out.flush();
 }
  public static void main(String[] args) throws Exception {
    time = System.currentTimeMillis();

    IN = System.in;
    OUT = System.out;
    in = new BufferedReader(new InputStreamReader(IN));
    out = new PrintWriter(OUT, FLUSH);
    solveOne();
    out.flush();
  }
Пример #14
0
 /**
  * Returns the date in seconds.
  *
  * @return seconds
  */
 final BigDecimal seconds() {
   int z = tz;
   if (z == Short.MAX_VALUE) {
     // [CG] XQuery, DateTime: may be removed
     final long n = System.currentTimeMillis();
     z = Calendar.getInstance().getTimeZone().getOffset(n) / 60000;
   }
   return (sec == null ? BigDecimal.ZERO : sec)
       .add(BigDecimal.valueOf(Math.max(0, hou) * 3600 + Math.max(0, min) * 60 - z * 60));
 }
Пример #15
0
  /**
   * TDTEngine - constructor for a new Tag Data Translation engine
   *
   * @param confdir the string value of the path to a configuration directory consisting of two
   *     subdirectories, <code>schemes</code> and <code>auxiliary</code>.
   *     <p>When the class TDTEngine is constructed, the path to a local directory must be
   *     specified, by passing it as a single string parameter to the constructor method (without
   *     any trailing slash or file separator). e.g. <code>
   *     <pre>TDTEngine engine = new TDTEngine("/opt/TDT");</pre></code>
   *     <p>The specified directory must contain two subdirectories named auxiliary and schemes. The
   *     Tag Data Translation definition files for the various coding schemes should be located
   *     inside the subdirectory called <code>schemes</code>. Any auxiliary lookup files (such as
   *     <code>ManagerTranslation.xml</code>) should be located inside the subdirectory called
   *     <code>auxiliary</code>.
   *     <p>Files within the schemes directory ending in <code>.xml</code> are read in and
   *     unmarshalled using <a href = "http://www.castor.org">Castor</a>.
   */
  public TDTEngine(String confdir)
      throws FileNotFoundException, MarshalException, ValidationException, TDTException {
    xmldir = confdir;

    long t = System.currentTimeMillis();
    File[] dir =
        new java.io.File(confdir + File.separator + "schemes").listFiles(new XMLFilenameFilter());
    // java.util.Arrays.sort(dir); // Sort it
    if (dir == null) throw new TDTException("Cannot find schemes in " + confdir);
    Unmarshaller unmar = new Unmarshaller();
    for (File f : dir) {
      EpcTagDataTranslation tdt =
          (EpcTagDataTranslation) unmar.unmarshal(EpcTagDataTranslation.class, new FileReader(f));

      initFromTDT(tdt);
    }

    // need to populate the hashmap gs1cpi from the ManagerTranslation.xml table in auxiliary.
    // Unmarshaller unmar = new Unmarshaller();
    GEPC64Table cpilookup =
        (GEPC64Table)
            unmar.unmarshal(
                GEPC64Table.class,
                new FileReader(
                    confdir
                        + File.separator
                        + "auxiliary"
                        + File.separator
                        + "ManagerTranslation.xml"));
    for (Enumeration e = cpilookup.enumerateEntry(); e.hasMoreElements(); ) {
      Entry entry = (Entry) e.nextElement();
      String comp = entry.getCompanyPrefix();
      String indx = Integer.toString(entry.getIndex());
      gs1cpi.put(indx, comp);
      gs1cpi.put(comp, indx);
    }

    // System.out.println("Loaded schemas in " +
    //		   (System.currentTimeMillis() - t)
    //		   + " millisecs");

  }
Пример #16
0
 /**
  * Standard Constructor
  *
  * @param ctx context
  * @param S_TimeExpenseLine_ID id
  * @param trx transaction
  */
 public MTimeExpenseLine(Ctx ctx, int S_TimeExpenseLine_ID, Trx trx) {
   super(ctx, S_TimeExpenseLine_ID, trx);
   if (S_TimeExpenseLine_ID == 0) {
     //	setS_TimeExpenseLine_ID (0);		//	PK
     //	setS_TimeExpense_ID (0);			//	Parent
     setQty(Env.ONE);
     setQtyInvoiced(Env.ZERO);
     setQtyReimbursed(Env.ZERO);
     //
     setExpenseAmt(Env.ZERO);
     setConvertedAmt(Env.ZERO);
     setPriceReimbursed(Env.ZERO);
     setInvoicePrice(Env.ZERO);
     setPriceInvoiced(Env.ZERO);
     //
     setDateExpense(new Timestamp(System.currentTimeMillis()));
     setIsInvoiced(false);
     setIsTimeReport(false);
     setLine(10);
     setProcessed(false);
   }
 } //	MTimeExpenseLine
Пример #17
0
  public static void main(String[] args) {
    long time;
    double answer;
    boolean errors = false;
    double desiredAnswer;

    time = System.currentTimeMillis();
    answer = new MarblePositioning().totalWidth(new int[] {1, 2, 3, 4, 5, 6, 7, 8});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 50.58155219373389;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new MarblePositioning().totalWidth(new int[] {7, 7, 7});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 28.0D;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new MarblePositioning().totalWidth(new int[] {10, 20, 30});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 62.92528739883945D;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new MarblePositioning().totalWidth(new int[] {100, 100, 11, 11, 25});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 200.0D;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer =
        new MarblePositioning()
            .totalWidth(new int[] {903214, 252429, 550970, 58607, 889016, 695517});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 4430821.778043712D;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();

    if (errors) System.out.println("Some of the test cases had errors :-(");
    else System.out.println("You're a stud (at least on the test data)! :-D ");
  }
Пример #18
0
  public int selectAction() {

    if (currentPath != -1) {
      if (nodePaths[currentPath].contains(currentNode)) {
        currentIndex = nodePaths[currentPath].indexOf(currentNode);
      }
    }
    if (firstStep) {

      pathLength = 0;
      // currentPath=generator.nextInt(paths.length);

      currentPath = selectCycle();
      previousPath = currentPath;
      System.out.println("New path is generated");
      System.out.println(currentPath);
      System.out.println(currentNode);
      firstStep = false;
      if (nodePaths[currentPath].contains(currentNode)) {
        pathLength++;
        currentIndex = nodePaths[currentPath].indexOf(currentNode);
        startTime = System.currentTimeMillis();
        cycleReward =
            cycleReward + payout - travelCost; // currentUtilitiesforVisitingNodes[currentNode];
        return paths[currentPath].get(currentIndex);

      } else {
        cycleReward = 0;

        return 0;
      }
    } else {
      if (currentIndex == 0 && nodePaths[currentPath].contains(currentNode)) {
        currentPath = selectCycle();
        previousPath = currentPath;
        pathLength = 0;

        System.out.println("New path is generated");
        System.out.println(currentPath);
        System.out.println(currentNode);
        firstStep = false;
        if (nodePaths[currentPath].contains(currentNode)) {
          pathLength++;
          currentIndex = nodePaths[currentPath].indexOf(currentNode);
          startTime = System.currentTimeMillis();
          cycleReward =
              cycleReward + payout - travelCost; // currentUtilitiesforVisitingNodes[currentNode];
          return paths[currentPath].get(currentIndex);
        } else {
          cycleReward = 0;
          return 0;
        }
      }
      // if(currentIndex==paths[currentPath].size()-1){

      //	firstStep=true;
      // }
      if (pathLength == paths[currentPath].size() - 1) {
        firstStep = true;
        endTime = System.currentTimeMillis();
        Rtmp = cycleReward * 1000 / (endTime - startTime);
        if (t < N) {
          Rmax = Math.max(Rmax, Rtmp);
        }
        if (t == N) {
          alpha = Rmax;
        }

        if (t > N) {
          alpha = lambda * alpha + (1 - lambda) * Rtmp;
        }
        t = t + 1;
      }
      return paths[currentPath].get(currentIndex);
    }
  }
Пример #19
0
  public static void main(String[] args) {
    long time;
    int[] answer;
    boolean errors = false;
    int[] desiredAnswer;

    boolean same;

    time = System.currentTimeMillis();
    answer = new HappyCells().getHappy(new String[] {"XXX", "X.X", "XXX"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = new int[] {1, 0, 0};
    System.out.println("Your answer:");
    if (answer.length > 0) {
      System.out.print("\t{ " + answer[0]);
      for (int i = 1; i < answer.length; i++) System.out.print(", " + answer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    System.out.println("Desired answer:");
    if (desiredAnswer.length > 0) {
      System.out.print("\t{ " + desiredAnswer[0]);
      for (int i = 1; i < desiredAnswer.length; i++) System.out.print(", " + desiredAnswer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    same = desiredAnswer.length == answer.length;
    for (int i = 0; i < answer.length && same; i++) if (answer[i] != desiredAnswer[i]) same = false;
    if (!same) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new HappyCells().getHappy(new String[] {"."});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = new int[] {1, 0, 0};
    System.out.println("Your answer:");
    if (answer.length > 0) {
      System.out.print("\t{ " + answer[0]);
      for (int i = 1; i < answer.length; i++) System.out.print(", " + answer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    System.out.println("Desired answer:");
    if (desiredAnswer.length > 0) {
      System.out.print("\t{ " + desiredAnswer[0]);
      for (int i = 1; i < desiredAnswer.length; i++) System.out.print(", " + desiredAnswer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    same = desiredAnswer.length == answer.length;
    for (int i = 0; i < answer.length && same; i++) if (answer[i] != desiredAnswer[i]) same = false;
    if (!same) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer =
        new HappyCells().getHappy(new String[] {"XXXXXX", "X.XXXX", "XXX.XX", "X..XXX", "XXXXXX"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = new int[] {1, 1, 1};
    System.out.println("Your answer:");
    if (answer.length > 0) {
      System.out.print("\t{ " + answer[0]);
      for (int i = 1; i < answer.length; i++) System.out.print(", " + answer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    System.out.println("Desired answer:");
    if (desiredAnswer.length > 0) {
      System.out.print("\t{ " + desiredAnswer[0]);
      for (int i = 1; i < desiredAnswer.length; i++) System.out.print(", " + desiredAnswer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    same = desiredAnswer.length == answer.length;
    for (int i = 0; i < answer.length && same; i++) if (answer[i] != desiredAnswer[i]) same = false;
    if (!same) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new HappyCells().getHappy(new String[] {"..."});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = new int[] {0, 0, 3};
    System.out.println("Your answer:");
    if (answer.length > 0) {
      System.out.print("\t{ " + answer[0]);
      for (int i = 1; i < answer.length; i++) System.out.print(", " + answer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    System.out.println("Desired answer:");
    if (desiredAnswer.length > 0) {
      System.out.print("\t{ " + desiredAnswer[0]);
      for (int i = 1; i < desiredAnswer.length; i++) System.out.print(", " + desiredAnswer[i]);
      System.out.println(" }");
    } else System.out.println("\t{ }");
    same = desiredAnswer.length == answer.length;
    for (int i = 0; i < answer.length && same; i++) if (answer[i] != desiredAnswer[i]) same = false;
    if (!same) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();

    if (errors) System.out.println("Some of the test cases had errors :-(");
    else System.out.println("You're a stud (at least on the test data)! :-D ");
  }
public class C {
  public static long time = 0;

  public static void main(String[] args) throws Exception {
    time = System.currentTimeMillis();

    IN = System.in;
    OUT = System.out;
    in = new BufferedReader(new InputStreamReader(IN));
    out = new PrintWriter(OUT, FLUSH);
    solveOne();
    out.flush();
  }

  public static void solveOne() throws Exception {
    int n = nextInt();
    int m = nextInt();
    int k = nextInt();
    int w = nextInt();
    char[][][] levels = new char[k][n][];
    ;
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < n; j++) {
        levels[i][j] = nextString().toCharArray();
      }
    }
    int[][] cost = new int[k][k];
    PriorityQueue<int[]> q =
        new PriorityQueue<>(
            k * k,
            new Comparator<int[]>() {
              @Override
              public int compare(int[] o1, int[] o2) {
                return o1[2] - o2[2];
              }
            });
    for (int i = 0; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        int[] cur = {i, j, diff(levels[i], levels[j]) * w};
        cost[i][j] = cur[2];
        q.add(cur);
        //              px("edge", cur);
      }
    }
    //      px(q.size());
    //      for (int[] e: cost) px(e);
    DisjointUnionSet djs = new DisjointUnionSet(k);
    boolean[][] al = new boolean[k][k];
    int finalCost = n * m * k;
    for (; q.size() > 0; ) {
      int[] edge = q.poll();
      int p1 = djs.getPartitionId(edge[0]);
      int p2 = djs.getPartitionId(edge[1]);
      //          px(edge, p1 == p2, edge[2]);
      if (edge[2] > n * m) break;
      if (p1 != p2) {

        djs.unionElement(edge[0], edge[1]);
        finalCost -= n * m - edge[2];
        al[edge[1]][edge[0]] = true;
        al[edge[0]][edge[1]] = true;
      }
    }
    //      for (boolean[] e: al) px(e);
    pn(finalCost);
    boolean[] ex = new boolean[k];
    for (int i = 0; i < k; i++) {
      if (!ex[i]) {
        dfs(i, -1, ex, k, al);
      }
    }
  }

  public static void dfs(int at, int from, boolean[] ex, int k, boolean[][] al) {
    ex[at] = true;

    pn((at + 1) + " " + (from + 1));
    for (int i = 0; i < k; i++) {
      if (!ex[i] && al[i][at]) {
        //              px(i, at);
        dfs(i, at, ex, k, al);
      }
    }
  }

  public static final int COST = 2;

  public static int diff(char[][] a, char[][] b) {
    int fin = 0;
    for (int i = 0; i < a.length; i++) {
      for (int j = 0; j < a[0].length; j++) {
        if (a[i][j] != b[i][j]) {
          fin++;
        }
      }
    }
    return fin;
  }

  public static class DisjointUnionSet {
    int[] parent;
    int[] rank;

    DisjointUnionSet(int length) {
      parent = new int[length];
      rank = new int[length];
      for (int i = 0; i < length; i++) parent[i] = i;
    }
    /*
     * Return the partition number.
     */
    int getPartitionId(int x) {
      if (parent[x] != x) parent[x] = getPartitionId(parent[x]);
      return parent[x];
    }
    /*
     * Join the two partion that "x" and "y" are in.
     */
    void unionElement(int x, int y) {
      int k1 = getPartitionId(x);
      int k2 = getPartitionId(y);
      if (k1 == k2) return;
      if (rank[k1] < rank[k2]) parent[k1] = k2;
      else if (rank[k1] > rank[k2]) parent[k2] = k1;
      else {
        parent[k2] = k1;
        rank[k1]++;
      }
    }
  }

  public static void solveTwo() throws Exception {}

  public static void solveThree() throws Exception {}

  public static BufferedReader in;
  public static StringTokenizer st;
  public static InputStream IN;
  public static OutputStream OUT;

  public static String nextString() throws Exception {
    for (; st == null || !st.hasMoreTokens(); ) {
      String k1 = in.readLine();
      if (k1 == null) return null;
      st = new StringTokenizer(k1);
    }
    return st.nextToken();
  }

  public static int nextInt() throws Exception {
    return Integer.parseInt(nextString());
  }

  public static long nextLong() throws Exception {
    return Long.parseLong(nextString());
  }

  public static double nextDouble() throws Exception {
    return Double.parseDouble(nextString());
  }

  private static int[] nextIntArray(int n1) throws Exception {
    int[] l1 = new int[n1];
    for (int i = 0; i < n1; i++) {
      l1[i] = nextInt();
    }
    return l1;
  }

  private static long[] nextLongArray(int n1) throws Exception {
    long[] l1 = new long[n1];
    for (int i = 0; i < n1; i++) {
      l1[i] = nextLong();
    }
    return l1;
  }

  private static int[][] nextIntGrid(int x, int y) throws Exception {
    int[][] l1 = new int[x][y];
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        l1[i][j] = nextInt();
      }
    }
    return l1;
  }

  public static void px(Object... l1) {
    System.out.println(Arrays.deepToString(l1));
  }

  public static boolean FLUSH = false;
  public static PrintWriter out;

  public static void p(Object... l1) {
    for (int i = 0; i < l1.length; i++) {
      if (i != 0) out.print(' ');
      out.print(l1[i].toString());
    }
  }

  public static void pn(Object... l1) {
    for (int i = 0; i < l1.length; i++) {
      if (i != 0) out.print(' ');
      out.print(l1[i].toString());
    }
    out.println();
  }

  public static void pn(Collection l1) {
    boolean first = true;
    for (Object e : l1) {
      if (first) first = false;
      else out.print(' ');
      out.print(e.toString());
    }
    out.println();
  }

  private static BigInteger bi(long n1) {
    return BigInteger.valueOf(n1);
  }

  private static double usedTime() {
    return (System.currentTimeMillis() - time) * 0.001;
  }

  private static Random usingRandomGenerator = new Random(System.currentTimeMillis());

  private static void sort(double[] l1) {
    for (int i = 0; i < l1.length; i++) {
      int q = i + usingRandomGenerator.nextInt(l1.length - i);
      double t = l1[i];
      l1[i] = l1[q];
      l1[q] = t;
    }
    Arrays.sort(l1);
  }

  private static void sort(int[] l1) {
    for (int i = 0; i < l1.length; i++) {
      int q = i + usingRandomGenerator.nextInt(l1.length - i);
      int t = l1[i];
      l1[i] = l1[q];
      l1[q] = t;
    }
    Arrays.sort(l1);
  }

  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);
  }
}
  public static void main(String[] args) {
    long time;
    int answer;
    boolean errors = false;
    int desiredAnswer;

    time = System.currentTimeMillis();
    answer = new TheQuestionsAndAnswersDivOne().find(2, new String[] {"No", "Yes"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 2;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new TheQuestionsAndAnswersDivOne().find(2, new String[] {"No", "No", "No"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 6;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new TheQuestionsAndAnswersDivOne().find(3, new String[] {"Yes", "No", "No", "Yes"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 12;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new TheQuestionsAndAnswersDivOne().find(3, new String[] {"Yes", "Yes", "Yes", "No"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 18;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();

    if (errors) System.out.println("Some of the test cases had errors :-(");
    else System.out.println("You're a stud (at least on the test data)! :-D ");
  }
  /** Business logic to execute. */
  public VOListResponse loadSupplierPriceItems(
      GridParams pars, String serverLanguageId, String username, ArrayList customizedFields)
      throws Throwable {
    PreparedStatement pstmt = null;
    Connection conn = null;
    try {
      if (this.conn == null) conn = getConn();
      else conn = this.conn;

      BigDecimal rootProgressiveHIE01 =
          (BigDecimal) pars.getOtherGridParams().get(ApplicationConsts.ROOT_PROGRESSIVE_HIE01);
      BigDecimal progressiveHIE01 =
          (BigDecimal) pars.getOtherGridParams().get(ApplicationConsts.PROGRESSIVE_HIE01);
      BigDecimal progressiveHIE02 =
          (BigDecimal) pars.getOtherGridParams().get(ApplicationConsts.PROGRESSIVE_HIE02);
      BigDecimal progressiveREG04 =
          (BigDecimal) pars.getOtherGridParams().get(ApplicationConsts.PROGRESSIVE_REG04);
      String companyCodeSYS01 =
          (String) pars.getOtherGridParams().get(ApplicationConsts.COMPANY_CODE_SYS01);
      String pricelistCodePUR03 =
          (String) pars.getOtherGridParams().get(ApplicationConsts.PRICELIST);

      CompanyHierarchyLevelVO vo =
          (CompanyHierarchyLevelVO) pars.getOtherGridParams().get(ApplicationConsts.TREE_FILTER);
      if (vo != null) {
        progressiveHIE01 = vo.getProgressiveHIE01();
        progressiveHIE02 = vo.getProgressiveHie02HIE01();
      }

      String sql =
          "select PUR02_SUPPLIER_ITEMS.COMPANY_CODE_SYS01,PUR02_SUPPLIER_ITEMS.ITEM_CODE_ITM01,PUR02_SUPPLIER_ITEMS.SUPPLIER_ITEM_CODE,PUR02_SUPPLIER_ITEMS.PROGRESSIVE_REG04,"
              + "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE02,PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE01,PUR02_SUPPLIER_ITEMS.MIN_PURCHASE_QTY,PUR02_SUPPLIER_ITEMS.MULTIPLE_QTY,"
              + "PUR02_SUPPLIER_ITEMS.UM_CODE_REG02,PUR02_SUPPLIER_ITEMS.ENABLED,SYS10_COMPANY_TRANSLATIONS.DESCRIPTION,REG02_MEASURE_UNITS.DECIMALS,"
              + "ITM01_ITEMS.VAT_CODE_REG01,SYS10_VAT.DESCRIPTION,REG01_VATS.DEDUCTIBLE,REG01_VATS.VALUE,"
              + "PUR04_SUPPLIER_PRICES.VALUE,PUR04_SUPPLIER_PRICES.START_DATE,PUR04_SUPPLIER_PRICES.END_DATE,"
              + "ITM01_ITEMS.USE_VARIANT_1,ITM01_ITEMS.USE_VARIANT_2,ITM01_ITEMS.USE_VARIANT_3,ITM01_ITEMS.USE_VARIANT_4,ITM01_ITEMS.USE_VARIANT_5, "
              + "ITM01_ITEMS.NO_WAREHOUSE_MOV "
              + " from PUR02_SUPPLIER_ITEMS,SYS10_COMPANY_TRANSLATIONS,ITM01_ITEMS,REG02_MEASURE_UNITS,SYS10_TRANSLATIONS SYS10_VAT,REG01_VATS,PUR04_SUPPLIER_PRICES where "
              + "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE02=? and "
              + "PUR02_SUPPLIER_ITEMS.UM_CODE_REG02=REG02_MEASURE_UNITS.UM_CODE and "
              + "PUR02_SUPPLIER_ITEMS.COMPANY_CODE_SYS01=ITM01_ITEMS.COMPANY_CODE_SYS01 and "
              + "PUR02_SUPPLIER_ITEMS.ITEM_CODE_ITM01=ITM01_ITEMS.ITEM_CODE and "
              + "ITM01_ITEMS.COMPANY_CODE_SYS01=SYS10_COMPANY_TRANSLATIONS.COMPANY_CODE_SYS01 and "
              + "ITM01_ITEMS.PROGRESSIVE_SYS10=SYS10_COMPANY_TRANSLATIONS.PROGRESSIVE and "
              + "SYS10_COMPANY_TRANSLATIONS.LANGUAGE_CODE=? and "
              + "PUR02_SUPPLIER_ITEMS.COMPANY_CODE_SYS01 = ? and "
              + "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_REG04=? and "
              + "PUR02_SUPPLIER_ITEMS.ENABLED='Y' and "
              + "ITM01_ITEMS.VAT_CODE_REG01=REG01_VATS.VAT_CODE and "
              + "REG01_VATS.PROGRESSIVE_SYS10=SYS10_VAT.PROGRESSIVE and "
              + "SYS10_VAT.LANGUAGE_CODE=? and "
              + "PUR02_SUPPLIER_ITEMS.COMPANY_CODE_SYS01=PUR04_SUPPLIER_PRICES.COMPANY_CODE_SYS01 and "
              + "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_REG04=PUR04_SUPPLIER_PRICES.PROGRESSIVE_REG04 and "
              + "PUR02_SUPPLIER_ITEMS.ITEM_CODE_ITM01=PUR04_SUPPLIER_PRICES.ITEM_CODE_ITM01 and "
              + "PUR04_SUPPLIER_PRICES.PRICELIST_CODE_PUR03=? and "
              + "PUR04_SUPPLIER_PRICES.START_DATE<=? and "
              + "PUR04_SUPPLIER_PRICES.END_DATE>? ";

      if (rootProgressiveHIE01 == null || !rootProgressiveHIE01.equals(progressiveHIE01)) {
        // retrieve all subnodes of the specified node...
        pstmt =
            conn.prepareStatement(
                "select HIE01_COMPANY_LEVELS.PROGRESSIVE,HIE01_COMPANY_LEVELS.PROGRESSIVE_HIE01,HIE01_COMPANY_LEVELS.LEV from HIE01_COMPANY_LEVELS "
                    + "where COMPANY_CODE_SYS01='"
                    + companyCodeSYS01
                    + "' and ENABLED='Y' and PROGRESSIVE_HIE02=? and PROGRESSIVE>=? "
                    + "order by LEV,PROGRESSIVE_HIE01,PROGRESSIVE");
        pstmt.setBigDecimal(1, progressiveHIE02);
        pstmt.setBigDecimal(2, progressiveHIE01);
        ResultSet rset = pstmt.executeQuery();

        HashSet currentLevelNodes = new HashSet();
        HashSet newLevelNodes = new HashSet();
        String nodes = "";
        int currentLevel = -1;
        while (rset.next()) {
          if (currentLevel != rset.getInt(3)) {
            // next level...
            currentLevel = rset.getInt(3);
            currentLevelNodes = newLevelNodes;
            newLevelNodes = new HashSet();
          }
          if (rset.getBigDecimal(1).equals(progressiveHIE01)) {
            newLevelNodes.add(rset.getBigDecimal(1));
            nodes += rset.getBigDecimal(1) + ",";
          } else if (currentLevelNodes.contains(rset.getBigDecimal(2))) {
            newLevelNodes.add(rset.getBigDecimal(1));
            nodes += rset.getBigDecimal(1) + ",";
          }
        }
        rset.close();
        pstmt.close();
        if (nodes.length() > 0) nodes = nodes.substring(0, nodes.length() - 1);
        if (rootProgressiveHIE01 != null || nodes.length() > 0)
          sql += " and PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE01 in (" + nodes + ")";
      }

      Map attribute2dbField = new HashMap();
      attribute2dbField.put("companyCodeSys01PUR02", "PUR02_SUPPLIER_ITEMS.COMPANY_CODE_SYS01");
      attribute2dbField.put("itemCodeItm01PUR02", "PUR02_SUPPLIER_ITEMS.ITEM_CODE_ITM01");
      attribute2dbField.put("supplierItemCodePUR02", "PUR02_SUPPLIER_ITEMS.SUPPLIER_ITEM_CODE");
      attribute2dbField.put("progressiveReg04PUR02", "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_REG04");
      attribute2dbField.put("progressiveHie02PUR02", "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE02");
      attribute2dbField.put("progressiveHie01PUR02", "PUR02_SUPPLIER_ITEMS.PROGRESSIVE_HIE01");
      attribute2dbField.put("minPurchaseQtyPUR02", "PUR02_SUPPLIER_ITEMS.MIN_PURCHASE_QTY");
      attribute2dbField.put("multipleQtyPUR02", "PUR02_SUPPLIER_ITEMS.MULTIPLE_QTY");
      attribute2dbField.put("umCodeReg02PUR02", "PUR02_SUPPLIER_ITEMS.UM_CODE_REG02");
      attribute2dbField.put("enabledPUR02", "PUR02_SUPPLIER_ITEMS.ENABLED");
      attribute2dbField.put("descriptionSYS10", "SYS10_COMPANY_TRANSLATIONS.DESCRIPTION");
      attribute2dbField.put("decimalsREG02", "REG02_MEASURE_UNITS.DECIMALS");

      attribute2dbField.put("vatCodeReg01ITM01", "ITM01_ITEMS.VAT_CODE_REG01");
      attribute2dbField.put("vatDescriptionSYS10", "SYS10_VAT.DESCRIPTION");
      attribute2dbField.put("deductibleREG01", "REG01_VATS.DEDUCTIBLE");
      attribute2dbField.put("valueREG01", "REG01_VATS.VALUE");
      attribute2dbField.put("valuePUR04", "PUR04_SUPPLIER_PRICES.VALUE");
      attribute2dbField.put("startDatePUR04", "PUR04_SUPPLIER_PRICES.START_DATE");
      attribute2dbField.put("endDatePUR04", "PUR04_SUPPLIER_PRICES.END_DATE");

      attribute2dbField.put("useVariant1ITM01", "ITM01_ITEMS.USE_VARIANT_1");
      attribute2dbField.put("useVariant2ITM01", "ITM01_ITEMS.USE_VARIANT_2");
      attribute2dbField.put("useVariant3ITM01", "ITM01_ITEMS.USE_VARIANT_3");
      attribute2dbField.put("useVariant4ITM01", "ITM01_ITEMS.USE_VARIANT_4");
      attribute2dbField.put("useVariant5ITM01", "ITM01_ITEMS.USE_VARIANT_5");

      attribute2dbField.put("noWarehouseMovITM01", "ITM01_ITEMS.NO_WAREHOUSE_MOV");

      ArrayList values = new ArrayList();
      values.add(progressiveHIE02);
      values.add(serverLanguageId);
      values.add(companyCodeSYS01);
      values.add(progressiveREG04);
      values.add(serverLanguageId);
      values.add(pricelistCodePUR03);
      values.add(new java.sql.Date(System.currentTimeMillis()));
      values.add(new java.sql.Date(System.currentTimeMillis()));

      // read from PUR02 table...
      Response answer =
          CustomizeQueryUtil.getQuery(
              conn,
              new UserSessionParameters(username),
              sql,
              values,
              attribute2dbField,
              SupplierPriceItemVO.class,
              "Y",
              "N",
              null,
              pars,
              50,
              true,
              customizedFields);
      if (answer.isError()) throw new Exception(answer.getErrorMessage());
      else return (VOListResponse) answer;

    } catch (Throwable ex) {
      Logger.error(
          username,
          this.getClass().getName(),
          "executeCommand",
          "Error while fetching supplier items list",
          ex);
      throw new Exception(ex.getMessage());
    } finally {
      try {
        pstmt.close();
      } catch (Exception exx) {
      }
      try {
        if (this.conn == null && conn != null) {
          // close only local connection
          conn.commit();
          conn.close();
        }

      } catch (Exception exx) {
      }
    }
  }
Пример #23
0
  public static void main(String[] args) {
    long time;
    int answer;
    boolean errors = false;
    int desiredAnswer;

    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("101101101");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 3;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("1111101");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 1;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("00000");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = -1;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("110011011");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 3;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("1000101011");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = -1;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new CuttingBitString().getmin("111011100110101100101110111");
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 5;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();

    if (errors) System.out.println("Some of the test cases had errors :-(");
    else System.out.println("You're a stud (at least on the test data)! :-D ");
  }
Пример #24
0
 static {
   if (debug) {
     startTime = System.currentTimeMillis();
     Runtime.getRuntime()
         .addShutdownHook(
             new Thread() {
               public void run() {
                 long totalTime = System.currentTimeMillis() - startTime;
                 System.err.println("==================================================");
                 System.err.println("STATS");
                 System.err.println("==================================================");
                 System.err.println("Time: " + totalTime + "ms");
                 double avg = nset_elems;
                 avg = avg / nset_clones;
                 System.err.println(
                     "set clones:        "
                         + nset_clones
                         + " / "
                         + (nset_clones + nset_inplace_updates)
                         + " ("
                         + avg
                         + ")");
                 avg = nlist_elems;
                 avg = avg / nlist_clones;
                 System.err.println(
                     "list clones:       "
                         + nlist_clones
                         + " / "
                         + (nlist_clones + nlist_inplace_updates)
                         + " ("
                         + avg
                         + ")");
                 avg = ndict_elems;
                 avg = avg / ndict_clones;
                 System.err.println(
                     "dictionary clones: "
                         + ndict_clones
                         + " / "
                         + (ndict_clones + ndict_inplace_updates)
                         + " ("
                         + avg
                         + ")");
                 avg = nrecord_elems;
                 avg = avg / nrecord_clones;
                 System.err.println(
                     "record clones:     "
                         + nrecord_clones
                         + " / "
                         + (nrecord_clones + nrecord_strong_updates)
                         + " ("
                         + avg
                         + ")");
                 long totalClones = nlist_clones + nset_clones + ndict_clones + nrecord_clones;
                 long totalStrongUpdates =
                     nlist_inplace_updates
                         + nset_inplace_updates
                         + ndict_inplace_updates
                         + nrecord_strong_updates;
                 double ratio = totalClones;
                 ratio = 100 * (ratio / (totalClones + totalStrongUpdates));
                 long totalElems = nset_elems + nlist_elems + ndict_elems + nrecord_elems;
                 avg = totalElems;
                 avg = (avg / (totalClones));
                 System.err.println("--------------------------------------------------");
                 System.err.println(
                     "Total clones: "
                         + totalClones
                         + " / "
                         + (totalClones + totalStrongUpdates)
                         + " ("
                         + ratio
                         + "%)");
                 System.err.println(
                     "Average Clone Size: " + totalElems + " / " + totalClones + " (" + avg + ")");
                 avg = total_ref_count;
                 avg = avg / total_population;
                 System.err.println("Avg Reference Count: " + avg);
                 System.err.println("--------------------------------------------------");
                 if (logRefCounts) {
                   for (Object[] p : refCounts) {
                     System.out.println(System.identityHashCode(p[0]) + " : " + p[1]);
                   }
                 }
               }
             });
   }
 }
 private static double usedTime() {
   return (System.currentTimeMillis() - time) * 0.001;
 }
Пример #26
0
  public static void main(String[] args) {
    long time;
    long answer;
    boolean errors = false;
    long desiredAnswer;

    time = System.currentTimeMillis();
    answer = new AvoidRoads().numWays(6, 6, new String[] {"0 0 0 1", "6 6 5 6"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 252L;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new AvoidRoads().numWays(1, 1, new String[] {});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 2L;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new AvoidRoads().numWays(35, 31, new String[] {});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 6406484391866534976L;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();
    time = System.currentTimeMillis();
    answer = new AvoidRoads().numWays(2, 2, new String[] {"0 0 1 0", "1 2 2 2", "1 1 2 1"});
    System.out.println("Time: " + (System.currentTimeMillis() - time) / 1000.0 + " seconds");
    desiredAnswer = 0L;
    System.out.println("Your answer:");
    System.out.println("\t" + answer);
    System.out.println("Desired answer:");
    System.out.println("\t" + desiredAnswer);
    if (answer != desiredAnswer) {
      errors = true;
      System.out.println("DOESN'T MATCH!!!!");
    } else System.out.println("Match :-)");
    System.out.println();

    if (errors) System.out.println("Some of the test cases had errors :-(");
    else System.out.println("You're a stud (at least on the test data)! :-D ");
  }