# UVa 133 - The Dole Queue --- # 題目大意 兩人從1開始一順一逆時鐘數分別走$k,m$步,並將停下的地方輸出並刪掉,直到沒人留下。注意刪掉是最後發生的,所以兩人交錯不會影響彼此。 --- # 題解 直接模擬過程,唯一比較難的地方是下標的處理。我們需要使0->n,n+1->1。若此時位置為i,寫成$(i+n-1)$$\%n+1$即可達到要求。 --- ```=C++ #include <bits/stdc++.h> #define ll long long #define pb push_back #define INF 2147483647 #define ft first #define sec second #define pr pair<int,int> #define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; int t ,n ,k ,m ,vis[25] ,cnt; inline bool check() { for(int i=1 ;i<=n ;i++) if(!vis[i]) return true; return false; } void sol(int &x ,int dir ,int move) { while(move) { x = (x+dir+n-1)%n+1; if(vis[x]) continue; move--; //cout << x << ' '; } } int main() { while(cin >> n) { cin >> k >> m; if(!n) return 0; memset(vis,0,sizeof(vis)); int p1=n ,p2=1; while(1) { sol(p1 ,1 ,k); sol(p2 ,-1 ,m); vis[p1] = vis[p2] = 1; if(p1==p2) printf("%3d",p1); else printf("%3d%3d",p1,p2); if(check()) cout << ','; else break; } cout << '\n'; } return 0; } ```