Question number: | 201712-2 |
Question name: | game |
time limit: | 1.0s |
Memory limit: | 256.0MB |
Problem Description: | Problem Description There are n children playing games in a circle, the children are numbered from 1 to n , the 2nd child sits in the clockwise direction of the 1st child, the 3rd child sits in the clockwise direction of the 2nd child,..., the 1st child Sitting in the clockwise direction of child n . Input format Enter a line, including two integers n and k , the meaning is as described in the title. Output format Output a line containing an integer that represents the number of the winning child. Sample input 5 2 Sample output 3 Sample input 7 3 Sample output 4 Data size and convention For all evaluation use cases, 1 ≤ n ≤ 1000 and 1 ≤ k ≤ 9. |
import java.util.Scanner;
public class 游戏 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int[] a =new int[n+1];
int count=n;
int i=1;
int num=1;
while(count!=1){
if(a[i]!=-1){
a[i]=num;
num++;
}
if(a[i]%k==0||a[i]%10==k){
a[i]=-1;
count--;
}
if(i<n){
i++;
}else{
i=1;
}
}
for(int j=1;j<=n;j++){
if(a[j]!=-1){
System.out.println(j);
}
}
}
}