toj 1410. Euclid's Game

http://202.113.2.5:57778/toj/showp1410.html

找奇异状态

代码:

import java.util.*;

import java.math.*;



public class Main {



	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n, m;

		while (true) {

			n = in.nextInt();

			m = in.nextInt();

			if (n == 0 && m == 0) {

				break;

			}

			int temp;

			if (n > m) {

				temp = n;

				n = m;

				m = temp;

			}

			if (n == 0) {

				System.out.println("Ollie wins");

				continue;

			}

			boolean firstwin = true;

			while (n > 0) {

				if (m % n == 0 || m / n >= 2) {

					if (firstwin == true) {

						System.out.println("Stan wins");

					} else {

						System.out.println("Ollie wins");

					}

					break;

				}



				temp = m - n;

				m = n;

				n = temp;

				if (firstwin == true) {

					firstwin = false;

				} else {

					firstwin = true;

				}



			}

		}

	}



}

 

你可能感兴趣的:(game)