Educational Codeforces Round 68 D.1-2-K Game
13022 단어 게임
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;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
조밀한 게임을 Scratch로 만들어 보았다. 그 1.2021년 1월 7일에 스가 총리가 긴급 사태 선언을 발령했습니다. 역시 「밀」이 좋지 않은 일이라고, 재차 생각했으므로 넷에서 보인 명작 을 마음대로 흉내내 Scratch로 만들어 보았습니다. <완성 이미지> 링크...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.