[模拟]uva-133 – The Dole Queue

突然发现好多人比自己聪明比自己优秀还比自己努力。。。好恐怖啊 每天珍惜这几个小时的学习时间吧

这个紫书的简单题写了好几天。。。真垃圾。。这种圆环模拟的题算是明白了 先-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;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇