Educational Codeforces Round 68 D.1-2-K Game

13022 단어 게임
D. 1-2-K Game
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i 
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 ≤ n ≤ 109, 3 ≤ k ≤ 109) — the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
input
4 0 3 3 3 3 4 4 4
output
Bob Alice Bob Alice
이 문제는 바둑 논제로 n미터 길이로 매번 1, 2, k미터를 움직일 수 있는 사람이 진다는 뜻이다.이 문제는 sg 함수로 규칙을 나타낼 수 있다.마지막으로 k%3=0시 원 게임 결과에 영향을 미칠 수 있음을 알 수 있다.그렇지 않으면 1, 2미터만 이동할 수 있는 결과와 같고 최종 결과는 %k+1를 통해 분류할 수 있으며%3의 k영향 결과는 k에서만 영향을 미칠 수 있고 나머지는%3을 통해 결과를 판단할 수 있다.AC 코드 자바
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	static StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(System.in));
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pr = new PrintWriter(new BufferedOutputStream(System.out));
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws NumberFormatException, IOException {
		int arr[] = new int[10000];
		int q = sc.nextInt();
		while (q-- > 0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			if(k%3==0) {
				n %= k+1;
				if(n==k) {
					System.out.println("Alice");
				}else {
					if(n%3==0) {
						System.out.println("Bob");					
					}else {
						System.out.println("Alice");
					}
				}
			}else {
				if(n%3==0) {
					System.out.println("Bob");					
				}else {
					System.out.println("Alice");
				}
			}
			
		}

	}

	private static int nextInt() {
		try {
			st.nextToken();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return (int) st.nval;
	}
}

좋은 웹페이지 즐겨찾기