'commit'
This commit is contained in:
38
TangDou/XiTi/1376.cpp
Normal file
38
TangDou/XiTi/1376.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//好题!
|
||||
//如果需要性能上的优化,防止TLE的话:https://blog.csdn.net/QQGUOsiBO/article/details/104215038
|
||||
int main() {
|
||||
//key:原来牌的位置索引,value是指牌的号
|
||||
map<int,int> _map;
|
||||
int n;
|
||||
cin >> n;
|
||||
queue<int> q;
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
q.push(i);
|
||||
}
|
||||
int count = 0;
|
||||
while (!q.empty()) {
|
||||
//弹出最上面
|
||||
int out = q.front();
|
||||
q.pop();
|
||||
//第几个出列了
|
||||
count++;
|
||||
_map[out] = count;
|
||||
//需要向后移动count+1张牌
|
||||
if (!q.empty()) {
|
||||
for (int i = 0; i < count + 1; ++i) {
|
||||
int t = q.front();
|
||||
q.pop();
|
||||
q.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
//遍历_map进行输出,因为_map是按key有序的,所以可以直接输出
|
||||
for(map<int,int>::iterator it=_map.begin();it!=_map.end();it++)
|
||||
cout<<it->second<<" ";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user