[Java] - 2016 Square Pasture. I missed some cases

On the Square Pasture problem in the 2016 USACO Bronze contest, some of the outputs for some cases are incorrect

2016 Bronze Square Pasture - USACO

My Work

import java.io.*;
import java.util.*;

public class main {
    public static void main(String[] args) throws IOException {

        Kattio io = new Kattio("square");

        //first pasture
        int x1 = io.nextInt();
        int y1 = io.nextInt();

        int x2 = io.nextInt(); //right corner x coords
        int y2 = io.nextInt();

        //second pasture
        int x3 = io.nextInt(); //left corner x coords
        int y3 = io.nextInt();

        int x4 = io.nextInt();
        int y4 = io.nextInt(); //left corner y coords, right corner y coords

        int totalDistance = (int) calDis(x3, y4, x2, y4);
        io.println((int) Math.pow(totalDistance, 2));
        io.close();

    }
    
    static double calDis(int x1,int y1,int x2,int y2)
	{
	    return (Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
	}

    //input method: Kattio
    static class Kattio extends PrintWriter {

        private BufferedReader r;
    
        private StringTokenizer st;
    
        // standard input
    
        public Kattio() { this(System.in,System.out); }
    
        public Kattio(InputStream i, OutputStream o) {
    
            super(o);
    
            r = new BufferedReader(new InputStreamReader(i));
    
        }
    
        // USACO-style file input
    
        public Kattio(String problemName) throws IOException {
    
            super(new FileWriter(problemName+".out"));
    
            r = new BufferedReader(new FileReader(problemName+".in"));
    
        }
    
        // returns null if no more input
    
        public String next() {
    
            try {
    
                while (st == null || !st.hasMoreTokens())
    
                    st = new StringTokenizer(r.readLine());
    
                return st.nextToken();
    
            } catch (Exception e) {}
    
            return null;
    
        }
    
        public int nextInt() { return Integer.parseInt(next()); }
    
        public double nextDouble() { return Double.parseDouble(next()); }
    
        public long nextLong() { return Long.parseLong(next()); }
    
    }
}

Find the top left corner coords + top right coords then using a method I made (basically just the distance formula) to find the distance between the points, and then squaring the result…

Question

What other cases were there that I missed?

Download the test cases and then you can find out about the cases you missed.

1 Like