(2017多校训练第一场)HDU - 6040 Hints of sd0061 nth

xiaoxiao2021-02-28  104

官方题解:

代码如下:

#include <bits/stdc++.h> using namespace std; typedef long long int LL; const int MOD = 998244353; const int MAX_N = 105; const int INF = 0x3f3f3f3f; struct Node { int val; int pos; bool operator < (const Node& a) const { return val < a.val || (val == a.val && pos < a.pos); } }; Node b[MAX_N]; unsigned a[10000005]; unsigned ans[MAX_N]; unsigned n, m, x, y, z; unsigned rng61() { unsigned t; x ^= x << 16; x ^= x >> 5; x ^= x << 1; t = x; x = y; y = z; z = t ^ x ^ y; return z; } int main() { //freopen("test.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin.sync_with_stdio(false); int Case = 1; while (cin >> n >> m >> x >> y >> z) { for (int i=1; i<=m; i++) { cin >> b[i].val; b[i].val++; b[i].pos = i; } b[m + 1].val = n + 1; sort(b + 1, b + m + 1); for (int i=1; i<=n; i++) a[i] = rng61(); for (int i=m; i>=1; i--) { nth_element(a + 1, a + b[i].val, a + b[i + 1].val); ans[b[i].pos] = a[b[i].val]; } cout << "Case #" << Case++ << ":"; for (int i=1; i<=m; i++) cout << ' ' << ans[i]; cout << endl; } return 0; }

转载请注明原文地址: https://www.6miu.com/read-47679.html

最新回复(0)