Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2012 -- CSC 2700 Section 02

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

week04/e/Bishop_10849.java

import java.util.Scanner;

/*
 *  Author: Son Pham
 *    Date: September 14, 2012
 * Purpose: This program calculates the minimum number
 *          of moves a bishop needs to reach a give square
 *          on a board.
 * Problem: 10849 Move The Bishop
 *
 *
 * Additional Comments: Got a horrible runtime. Wondering if
 *                      Scanner is at fault. Also, I forgot to
 *                      remove Try Catch blocks.
 */


public class Bishop_10849 {
    
    public static void determine(int x1, int y1, int x2 , int y2){
        if ((x1 == x2) && (y1 == y2))
            System.out.println("0");
        else if (((x1+y1)%2) != ((x2+y2)%2))
            System.out.println("no move");
        else if ((Math.abs(y2-y1)) == (Math.abs(x2-x1)))
            System.out.println("1");
        else
            System.out.println("2");
    }
    
    public static void main(String[] args){
        try{
            Scanner sc = new Scanner(System.in);
            int tc = sc.nextInt();
            while (tc > 0){
                sc.nextLine();
                int c = sc.nextInt();
                int n = sc.nextInt();
                while (c > 0){
                    int x1 = sc.nextInt();
                    int y1 = sc.nextInt();
                    int x2 = sc.nextInt();
                    int y2 = sc.nextInt();
                    determine(x1,y1,x2,y2);
                    --c;
                }
                --tc;
            }
        }
        catch(Exception ex){}
    }
}

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 Isaac Traxler