https://icpcarchive.ecs.baylor.edu/external/65/6501.pdf

조영준

풀다가 fail...
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class HelloWorld {
	public static void main(String[] args) {
		Scanner scanner;
		try {
			scanner = new Scanner(new File("input.txt"));
		} catch (FileNotFoundException e) {
			System.out.println(":(");
			scanner = new Scanner(System.in);
		}
		int case_size = scanner.nextInt();
		
		for (int i = 0; i < case_size; i++) {
			System.out.println("---");
			int bucketASize = scanner.nextInt();
			int bucketBSize = scanner.nextInt();
			int bucketAVolumn = scanner.nextInt();
			int bucketBVolumn = scanner.nextInt();
			int operation_size = scanner.nextInt();
			
			int[] originalPosition = {bucketAVolumn, bucketBVolumn};

			int gcd = gcd(bucketASize, bucketBSize);
			
			for (int j = 0; j < operation_size; j++) {
				int targetAVolumn = scanner.nextInt();
				int targetBVolumn = scanner.nextInt();
				
				if (targetAVolumn == originalPosition[0] && targetBVolumn == originalPosition[1]) {
					System.out.println("1");
				} else if (targetAVolumn == 0 || targetAVolumn == bucketASize) {
					if (targetBVolumn % gcd == 0) {
						System.out.println("3");
					} else {
						System.out.println("2");
					}
					
				} else if (targetBVolumn == 0 || targetBVolumn == bucketBSize) {
					if (targetAVolumn % gcd == 0) {
						System.out.println("3");
					} else {
						System.out.println("2");
					}
				} else {
					System.out.println("x");
				}
			}
		}
	}
	
	public static int gcd(int a, int b) {
		while (b != 0) {
			int temp = a % b;
			a = b;
			b = temp;
		}
		
		return Math.abs(a);
	}
}

 
Retrieved from http://wiki.zeropage.org/wiki.php/ACM_ICPC/Problems/6501
last modified 2021-02-07 05:22:20