【BZOJ 4104】【Thu Summer Camp 2015】解密运算

时间:2023-12-12 10:29:38

http://www.lydsy.com/JudgeOnline/problem.php?id=4104

网上题解满天飞,我也懒得写了【BZOJ 4104】【Thu Summer Camp 2015】解密运算

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 200003;
int in() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = (k << 3) + (k << 1) + c - '0';
return k * fh;
} struct node {
int num, kth;
bool operator < (const node &A) const {
return num == A.num ? kth < A.kth : num < A.num;
}
} Q[N];
int n, m; int main() {
n = in(); m = in();
for(int i = 0; i <= n; ++i) Q[i].num = in(), Q[i].kth = i; sort(Q, Q + n + 1); int tmp = Q[0].kth;
for(int i = 1; i <= n; ++i) printf("%d ", Q[tmp].num), tmp = Q[tmp].kth; puts("");
return 0;
}

好虐心的一道题,看了一晚上QwQ【BZOJ 4104】【Thu Summer Camp 2015】解密运算