题目背景
faebdc和zky在玩一个小游戏
题目描述
zky有n个扑克牌,编号从1到n,zky把它排成一个序列,每次把最上方的扑克牌放在牌堆底,然后把下一张扑克牌拿出来输出,最终输出的序列恰好是从1到n,faebdc问你原序列是什么,因为faebdc神犇早已在O(1)的时间得出结果,如果你在1s内答不出来,faebdc会吃了你。
输入格式
一个数n,表示扑克数目(n<=1000000)
输出格式
n个数,表示扑克序列
输入输出样例
输入 #1
13
输出 #1
7 1 12 2 8 3 11 4 9 5 13 6 10
说明/提示
各个测试点1s
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
#include<math.h>
#include<climits>
#include <map>
using namespace std;
int k,n,m = 0;
int a[1000010];
int main(){
ios_base::sync_with_stdio(0); // 让cin变快
cin.tie(0); // 让cin变快
cin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= 2; j++ ) {
m++;
if(m > n) m = 1;
if(a[m] != 0 ) j--;
}
a[m] = i;
}
for(int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
本文介绍了一个有趣的扑克序列谜题,zky通过特定的操作将扑克牌重新排列,faebdc挑战读者找出原始的扑克牌序列。文章提供了算法实现,帮助读者理解如何在限定时间内解决这个问题。
377

被折叠的 条评论
为什么被折叠?



