突然发现好多人比自己聪明比自己优秀还比自己努力。。。好恐怖啊 每天珍惜这几个小时的学习时间吧
这个紫书的简单题写了好几天。。。真垃圾。。这种圆环模拟的题算是明白了 先-1再+1 是一个好办法 学到了
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<ctime>
#include<map>
#include<stack>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 25;
int n, k, m;
bool vis[maxn];
int go(int p, int d, int t) {
while (t--) {
do {
p = (p + d + n - 1) % n + 1;//-1再+1是为了避免n的情况
} while (vis[p] == 1);//访问过跳过
}
return p;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int kk, mm, cnt;
while (cin >> n >> k >> m) {
if (n == 0) break;//特判
cnt = n;//剩余数=n
kk = n;
mm = 1;
memset(vis, 0, sizeof(vis));//重置数组
while (cnt) {
kk = go(kk, 1, k);
mm = go(mm, -1, m);
printf("%3d", kk);
cnt--;
if (kk != mm) {
printf("%3d", mm);
cnt--;
}
vis[kk] = vis[mm] = 1;//访问过
if (cnt) printf(",");
}
printf("\n");
}
return 0;
}







Comments | NOTHING