Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Spring 2015 -- CSC 2700 Section 01

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

week06/i/Deck.java

/*
 *  Author: Son Pham
 *    Date: February 19, 2013
 * Purpose: Solves this problem using the simplest approach.
 * Problem: 651 - Deck
 * Comment: The "two spaces between the words" is misleading and a bunch of
 *          bullcrap! It's one space between # Cards Overhang.
 */
import java.util.Scanner;

public class Deck {

    public static void main(String[] args) {
        double[] solutions = new double[100000];
        initSolutions(solutions);
        Scanner reader = new Scanner(System.in);
        System.out.println("# Cards Overhang");
        while(reader.hasNext()){
            int cards = Integer.parseInt(reader.next());
            double overhang = solutions[cards];
            System.out.printf("%5d     %.3f\n", cards,overhang);
        }
    }
    
    public static void initSolutions(double[] d){
        d[0] = 0;
        for(int i = 1; i < d.length; i++)
            d[i] = d[i-1] + (1.0/(2*i));
    }
}

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015