public class Test {
public static void main(String[] args) {
int n = 7;
int[] circle1 = new int[n+1];//正向圈
int[] circle2 = new int[n+1];//反向圈
int[] status = new int[n+1]; //标志是否出队
int k = 2;
int m = 3;
int found = 0;
//初始化正反向圈
for(int i=1;i<=n;i++){
circle1[i] = i;
circle2[i] = n+1-i;
status[i] = 0;
}
while(found < n){
int i=1;
int j=1;
int c1=0;
int c2=0;
for(;;i++){
if(status[circle1[i]]!=1){
c1++;
}
if(c1 == k){
found++;
break;
}
if(i==n) i=0;
}
for(;;j++){
if(status[circle2[j]]!=1){
c2++;
}
if(c2 == m){
if(circle2[i] != circle2[j]) found++;
break;
}
if(j==n) j=0;
}
status[circle1[i]] = 1;
status[circle2[j]] = 1;
if(circle1[i] == circle2[j]){
System.out.println(circle1[i]+"出局");
}else{
System.out.println(circle1[i]+"出局");
System.out.println(circle2[j]+"出局");
}
}
}
}
【模拟】【环形数组】-UVA-133- The Dole Queue |java实现
最新推荐文章于 2017-05-26 11:04:49 发布