11242 - Tour de France

All about problems in Volume CXII. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

11242 - Tour de France

Postby sith » Thu Jun 28, 2012 7:39 pm

Hello,
I've got WA, Why?

Code: Select all
import java.io.*;
import java.util.*;

class Main {


    public static void main(String[] args) {
     
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1024 * 1024);

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

//        String line;
        Scanner scanner = new Scanner(reader);
        try {
            while (scanner.hasNextInt()) {


                int front = scanner.nextInt();

                if (front == 0) {
                    break;
                }

                int rear = scanner.nextInt();

                int[] frontTeeths = new int[front];
                int[] rearTeeths = new int[rear];


                for (int i = 0; i < frontTeeths.length; i++) {
                    frontTeeths[i] = scanner.nextInt();

                }
                for (int i = 0; i < rearTeeths.length; i++) {
                    rearTeeths[i] = scanner.nextInt();
                }

                PriorityQueue<Double> d = new PriorityQueue<Double>();
                for (int frontTeeth : frontTeeths) {
                    for (int rearTeeth : rearTeeths) {
                        d.add((double) rearTeeth / frontTeeth);

                    }
                }
                PriorityQueue<Double> result = new PriorityQueue<Double>(100, new Comparator<Double>() {
                    public int compare(Double o1, Double o2) {
                        return o2.compareTo(o1);
                    }
                });


                double diff = 0;
                double D1 = 0, D2 = 0;

                Double d1 = d.poll();
                Double d2;
                while (d.size() > 0) {
                    d2 = d.poll();

                    double newDiff = d2 - d1;
                    if (newDiff > diff) {
                        D1 = d1;
                        D2 = d2;
                        diff = newDiff;
                    }
                    d1 = d2;
                }
                writer.write(String.format("%.2f", (D2 / D1)));
                writer.write("\n");
            }
            writer.flush();
        } catch (IOException e) {
        }
    }
}
sith
Learning poster
 
Posts: 67
Joined: Sat May 19, 2012 7:46 pm

Re: 11242 - Tour de France

Postby brianfry713 » Fri Jun 29, 2012 12:23 am

Input:
Code: Select all
2 2
40 40
10 10
0
AC output: 1.00
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11242 - Tour de France

Postby invadrFlip » Mon Aug 13, 2012 1:16 am

My program returns 1.0 for that input. Is this not the same thing? I did this to convert the original float to a float rounded to two decimals:

max *= 100;
max = Math.round(max);
max /= 100;

So anything that resembles this, "1.10 or 2.80 or 0.10 or 1.00 ..etc" would crop the last 0 when output. I'm using java by the way...
Any ideas?
invadrFlip
New poster
 
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 11242 - Tour de France

Postby brianfry713 » Mon Aug 13, 2012 11:17 pm

For each test case, output the maximum spread rounded to two decimal places. 1.00 is not judged the same as 1.0
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume CXII

Who is online

Users browsing this forum: No registered users and 1 guest