1016 Roliygu and Yilan

这篇文章讨论了在一个nxn棋盘上,Roliygu先手与Yilan下棋的游戏规则。两人轮流移动石子至未访问的邻格,谁无法移动即输。当棋盘为偶数或奇数大小时,根据移动次数的奇偶性预测赢家。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

Roliygu is famous because he likes to play games. Today he puts a chessboard in the desktop,and plays a game with Yilan. The size of the chessboard is n by n. A stone is placed in a corner square. They play alternatively with Roliygu having the first move. Each time,player is allowed to move the stone to an unvisited neighbor square horizontally or vertically. The one who can't make a move will lose the game. If both play perfectly, who will win the game?

翻译:Roliygu 之所以出名,是因为他喜欢玩游戏。今天,他在桌面上放了一个棋盘,和伊兰下了一场游戏。棋盘的大小是 n x n。一块石头被放置在一个角落的正方形中。他们交替玩,Roliygu 先走一步。每次,玩家都可以将石头水平或垂直移动到未访问的相邻方格。不能出手的人将输掉比赛。如果两人都打得很完美,谁会赢得比赛?

输入描述

The input is a sequence of positive integers each in a separate line. The integers are between 1 and 10 000,inclusive,indicating the size of the chessboard. The end of the input is indicated by a zero.

翻译:输入是正整数序列,每个整数在单独的行中。整数介于 1 和 10 000 之间,表示棋盘的大小。输入的末尾用零表示。

输出描述

Output the winner("Roliygu" or "Yilan") for each input line except the last zero. No other characters should be inserted in the output.

翻译:输出除最后一个零之外的每条输入行的获胜者(“Roliygu”或“Yilan”)。不应在输出中插入其他字符。

样例输入
2
0
样例输出
Roliygu
提示

染色问题

逻辑:棋盘为n*n规格,棋盘中有一个石子进行移动,两人移动的很完美说明每个棋格都走过,所以移动次数为(n*n-1)。当n为偶数时,移动次数为奇数,Roliygu先走,最后Yilan会无移动次数,Roliygu获胜。当n为奇数,同理Yilan获胜。

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    while(n!=0){
      if(n%2 == 0){
        System.out.println("Roliygu");
      }
      else if(n%2 != 0){
        System.out.println("Yilan");
      }
      n = scanner.nextInt();
    }
  }
}