CodeJam Solution - Round1A 2008, Problem A.Minimum Scalar Product

Round1A 2008, Problem A.Minimum Scalar Product

Simply I noticed that there ain't many open solutions, EVEN I thought that there's no needs for open solutions because the open ones might not correct in some ways and might not a good approach to the answer.
However, I post my own solution to share a way to solve CodeJam problems regardless of efficiency neither greatness.
Be noticed that this does NOT contain all the details because it's an indirect proof that you are familiar with JAVA, other computer languages or basic algorithms since you looked up "codejam" or found this post with other relative words.

RESOURCE
  1. CodeJam Practice Mode-Round1A 2008, Problem A.Minimum Scalar Product
  2. My Solution Code - HERE

 SOLUTION
  1. To make minimum scalar, the biggest element from an Array should be multiplied by the smallest one from another Array, and each multiplied item should be summed and you need to make an output.
  2. The easiest way to set an array from the smallest to the biggest is to use a method '.sort()' of Array Java general library
  3. then, you can just make a loop for approaching to every index from 0 to the end and multiply the other array index from the end to the very first, 0.
  4. and then, sum all of them.
  5. Make a list with ' "Case #"+ caseIndex +": "+ sumMultipliedOnes' or so.
    The output you make should start "Case #"
  6. To make a output file, use 'writeFile' method from 'InFileIO' class in my source.

ESSENCIAL CODES
  1. String[] aFileContent = InFileIO.readFile("./docs/A-large-practice.in");
    Using InFileIO.readFile, load a input file named "A-large-practice.in".
    All the lines in the input are stored on a String Array and we access every value with index.
  2. Implement proper codes for every input line.
    1. The first input line, index "0" is Case T.
      That's not necessary - you may ignore the index 0.
  3. From the index 1 to the very end, the input file serves the number of T sets of Vector count, Vector Array1, and Vector Array2.
    However, the Array is not completely an array. they are like "1 2 43 45" - just set of numbers identified with space between each number, Not with comma- ",".
    1. if( Index No%3 ==1) is a vector number set which a case contains items' count - you may ignore because we can put them an ArrayList or Array and see the size, using "ArrayList.size()" or "Array.length"
    2. if( Index No%3 ==2), and if( Index No%3 ==0) is also another Array, a set of Vectors. To make them a real array, use 'Array.slice(" ")', and to make them in order, use '.sort()' method.
  4. You get all ready.
    Make a loop for approaching every index, and multiply, sum all of them as mentioned in SOLUTION  section.
* YOU'D BETTER SEE THE ACTUAL CODES RATHER THEN LITERAL EXPLANATION. PLEASE FINE THE SOURCE CODE, HERE*


:)

ONE CODE, TWO CORRECTS!!

A-Small : Correct !!

A-Large : Correct !!


댓글

가장 많이 본 글