好久没做题了,现在做一道都这么费劲。。。用数组模拟的。。。调了好一会。。
//============================================================================
// Name : 133.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int flag[100];
int N, k, m, t1, t2;
int Num(){
int num = 0;
for(int i = 1;i <= N;i++){
if(flag[i] == 0) num++;
}
return num;
}
int main() {
freopen("a.txt", "r", stdin);
while(scanf("%d%d%d", &N, &k, &m)&&(N||k||m)){
memset(flag, 0, sizeof(flag));
int p1, p2;
p1 = 1;
p2 = N;
while(Num()){
t1 = 1;
while(t1 < k){
while(flag[p1]){
if(p1!=N) p1++;
else p1 = 1;
}
t1++;
if(p1!=N) p1++;
else p1 = 1;
while(flag[p1]){
if(p1!=N) p1++;
else p1 = 1;
}
}
t2 = 1;
while(t2 < m){
while(flag[p2]){
if(p2!=1) p2--;
else p2 = N;
}
t2++;
if(p2!=1) p2--;
else p2 = N;
while(flag[p2]){
if(p2!=1) p2--;
else p2 = N;
}
}
//printf("%d %d\n", p1, p2);
// if(Num() == 8) break;
// printf("%d %d %d %d %d\n", p1, p2, t1, t2, Num());
if(p1 != p2){
if(Num() == 2){
printf("%3d%3d\n", p1, p2);
break;
}
else printf("%3d%3d,", p1, p2);
flag[p1] = 1;
flag[p2] = 1;
while(flag[p1]){
if(p1!=N) p1++;
else p1 = 1;
}
while(flag[p2]){
if(p2!=1) p2--;
else p2 = N;
}
}
else{
if(Num() == 1){
printf("%3d\n", p1);
break;
}
else printf("%3d,", p1);
flag[p1] = 1;
while(flag[p1]){
if(p1!=N) p1++;
else p1 = 1;
}
while(flag[p2]){
if(p2!=1) p2--;
else p2 = N;
}
}
}
}
return 0;
}