2746:约瑟夫问题 百练noi
作者:互联网
import java.util.Scanner; public class Main { public static int flag[]=new int[305]; public static void init(){ for(int i=0;i<305;i++){ flag[i]=0; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n,m; n=sc.nextInt(); m=sc.nextInt(); while(n!=0 && m!=0){ int index=-1; int count=0; init(); for(int i=1;i<n;i++){ count=0; while(count!=m){ index=(index+1)%n; if(flag[index]==0){ count++; if(count==m){ flag[index]=1; } } } } for(int j=0;j<n;j++){ if(flag[j]==0){ System.out.println(j+1); break; } } n=sc.nextInt(); m=sc.nextInt(); } } }
标签:Main,java,noi,int,util,static,2746,百练,public 来源: https://www.cnblogs.com/fujinyu/p/14616326.html