救济金发放(UVa133)

时间:2024-12-18 00:03:44

  题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=69

C++11代码如下:

 #include<iostream>
#include<iomanip>
using namespace std;
int que[];
int n, k, m; int go(int p, int d, int t) { //d表示步长,值为1表示逆时针,-1表示顺时针
while (t--) {
do {
p = (p + d + n - ) % n + ; //防止(p+d)%n==0,(p+d+n-1)相当于旋转一周,最后加1
} while (que[p]==);
}
return p;
}
int main() {
while ((cin >> n >> k >> m) && n != ) {
for (int i = ; i <= n; i++) que[i] = i;
int left = n; //剩下的人数
int p1 = n, p2 = ; //起始位置
while (left) {
p1 = go(p1, , k);
p2 = go(p2, -, m);
cout << setw() << p1;
left--;
if (p1 != p2) {
cout << setw() << p2;
left--;
}
que[p1] = que[p2] = ;
if (left) cout << ',';
}
cout << endl;
}
return ;
}