UVA 10963 – The Swallowing Ground

Really really simple problem. Need to remember not to make incorrect assumptions. Problem gets easily solved once you use absolute values and you read the question again which tells you to print a blank line between outputs. :[

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 
 * @author Sanchit M. Bhatnagar
 * @see http://uhunt.felix-halim.net/id/74004
 * 
 */
public class P10963 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int W = sc.nextInt();
		for (int i = 0; i < W; i++) {
			int C = sc.nextInt();
			boolean bad = false;
			int last = Math.abs(sc.nextInt() - sc.nextInt());
			for (int j = 1; j < C; j++) {
				int tmp = Math.abs(sc.nextInt() - sc.nextInt());
				if (last != tmp)
					bad = true;
			}
			if (bad) {
				out.println("no");
			} else {
				out.println("yes");
			}
			if (i < W-1)
				out.println();
		}

		out.close();
		sc.close();
	}

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.