求代码,谢谢
#include <bits/stdc++.h> using namespace std; queue man, w; int main() { freopen("D.in","r",stdin); freopen("D.out","w",stdout); int n, m, k; cin >> n >> m >> k; for(int i=1;i<=n;i++) man.push(i); for(int i=1;i<=m;i++) w.push(i); while(k--){ printf("%d %d\n",man.front(), w.front()); man.push(man.front()); man.pop(); w.push(w.front()); w.pop(); } return 0; }
用队列
共 3 条回复
#include <bits/stdc++.h> using namespace std; queue man, w; int main() { freopen("D.in","r",stdin); freopen("D.out","w",stdout); int n, m, k; cin >> n >> m >> k; for(int i=1;i<=n;i++) man.push(i); for(int i=1;i<=m;i++) w.push(i); while(k--){ printf("%d %d\n",man.front(), w.front()); man.push(man.front()); man.pop(); w.push(w.front()); w.pop(); } return 0; }
用队列