7 solutions
-
1
强力推荐,无数组/队列
#include <bits/stdc++.h> using namespace std; int summan,sumwoman,man=1,woman=1,n; int main(){ cin>>summan>>sumwoman>>n; for(int i=0;i<n;i++){ cout<<man<<" "<<woman<<endl; man++; woman++; if(man>summan)man=1; if(woman>sumwoman)woman=1; } return 0; }
-
0
强效三合一,马上AC!
great 3 IN 1, AC now!
be最tt推er荐 优先队列dequeue
#include <bits/stdc++.h> using namespace std; int a, b, n; // 定义队列A和B deque<int> listA; deque<int> listB; int main() { cin >> a >> b >> n; // 将跳舞的人的编号依次加入队列A和B for (int i = 1; i <= a; i++) listA.push_back(i); for (int i = 1; i <= b; i++) listB.push_back(i); // 在类似“n组测试数据”这种需要重复执行算法部分的外层循环建议使用while,使用for有可能外层循环变量(i)和内层循环变量重名而导致错误,使用while可以降低发生概率 while (n--) { int nowA = listA.front(), nowB = listB.front(); // 获取现在要跳舞的人的编号 cout << nowA << " " << nowB << endl; // 跳舞 listA.push_back(nowA); listB.push_back(nowB); // 将跳过舞的人重新排队至队末 listA.pop_front(); listB.pop_front(); // 将跳过舞还待在队头赖着不走的人扔出去 } return 0; }
数组
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; // ↘A和B的长度 ↙ int a, b, alen, blen, afront = 1, bfront = 1, n; // ↑A和B的队头所在下标 ↑ int listA[N]; int listB[N]; int main() { cin >> a >> b >> n; // 将跳舞的人的代号依次加入队列A和B for (int i = 1; i <= a; i++) listA[++alen] = i; for (int i = 1; i <= b; i++) listB[++blen] = i; while (n--) { int nowA = listA[afront], nowB = listB[bfront]; // 获取现在要跳舞的人的编号 cout << nowA << " " << nowB << endl; // 跳舞 listA[++alen] = nowA; listB[++blen] = nowB; // 将跳过舞的人重新排队至队末 afront++, bfront++; // 将跳过舞还待在队头赖着不走的人扔出去 } return 0; }
s最h不i推t荐 队列queue
#include <bits/stdc++.h> using namespace std; int a, b, n, ai, bi; queue<int> listA; queue<int> listB; int main() { cin >> a >> b >> n; for (int i = 1; i <= a; i++) listA.push(i); for (int i = 1; i <= b; i++) listB.push(i); while (n--) { int nowA = listA.front(), nowB = listB.front(); cout << nowA << " " << nowB << endl; listA.push(nowA); listB.push(nowB); listA.pop(); listB.pop(); } return 0; }
-
0
#include<iostream> #include<queue> using namespace std; queue<int>q1; queue<int>q2; int main(){ int a,b,c; cin>>a>>b>>c; for(int i=1;i<=a;i++){ q1.push(i); } for(int i=1;i<=b;i++){ q2.push(i); } for(int i=1;i<=c;i++){ cout<<q1.front()<<" "<<q2.front()<<endl; q1.push(q1.front()); q1.pop(); q2.push(q2.front()); q2.pop(); } }
-
0
一次就对的大水题
#include<iostream> #include<queue> using namespace std; int main() { queue<int>man; queue<int>wom; int a,b,t; cin>>a>>b>>t;//输入 for(int i=0;i<a;i++)man.push(i+1); for(int i=0;i<b;i++)wom.push(i+1); for(int i=0;i<t;i++) { cout<<man.front()<<" "<<wom.front()<<endl;//输出 man.push(man.front());//轮流排 wom.push(wom.front());//轮流排 man.pop(); wom.pop(); } return 0;//完结散花 }
-
0
宇宙无敌超级代码
#include<bits/stdc++.h> using namespace std; queue<int> a1; queue<int> a2; int main(){ int a,b; int n; cin>>a>>b>>n; for(int i=1;i<=a;i++) a1.push(i); for(int i=1;i<=b;i++) a2.push(i); for(int i=1;i<=n;i++){ cout<<a1.front()<<' '<<a2.front()<<endl; a1.push(a1.front()); a2.push(a2.front()); a1.pop(); a2.pop(); } return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; int main(){ queue<unsigned long long> man,lady; long long m,l,d,ma,la; cin>>m>>l>>d; for(int i=1;i<=m;i++){ man.push(i); } for(int i=1;i<=l;i++){ lady.push(i); } for(int i=1;i<=d;i++){ cout<<man.front()<<" "<<lady.front()<<endl; ma=man.front(); la=lady.front(); man.pop(); lady.pop(); man.push(ma); lady.push(la); } return 0; }
MANwhat can I say!
- 1
Information
- ID
- 817
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 81
- Accepted
- 42
- Uploaded By