C. Jon Snow and his Favourite Number
链接:
http://codeforces.com/contest/768/problem/C
题解:
根据题意,其肯定会有循环节,先模拟,然后判断一下其是否到某一次时,其最大最小值达到稳定
代码:
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstring> 10 #include <iostream> 11 #include <algorithm> 12 #include <functional> 13 using namespace std; 14 #define rep(i,a,n) for (int i=a;i<=n;i++) 15 #define per(i,a,n) for (int i=n;i>=a;i--) 16 #define pb push_back 17 #define mp make_pair 18 #define all(x) (x).begin(),(x).end() 19 #define fi first 20 #define se second 21 #define SZ(x) ((int)(x).size()) 22 typedef vector<int> VI; 23 typedef long long ll; 24 typedef pair<int, int> PII; 25 const ll mod = 1000000007; 26 // head 27 28 const int maxn = 1e5 + 7; 29 int a[maxn], maxx[maxn], minn[maxn]; 30 31 int main() { 32 int n, k, x; 33 cin >> n >> k >> x; 34 rep(i, 1, n) cin >> a[i]; 35 sort(a + 1, a + 1 + n); 36 maxx[1] = a[n]; 37 minn[1] = a[1]; 38 rep(i, 1, k) { 39 sort(a + 1, a + 1 + n); 40 maxx[i] = a[n]; 41 minn[i] = a[1]; 42 if (i >= 3) { 43 if (maxx[i] == maxx[i - 1] && minn[i] == minn[i - 1] && 44 maxx[i] == maxx[i - 2] && minn[i] == minn[i - 2] && 45 maxx[i] == maxx[i - 3] && minn[i] == minn[i - 3]) { 46 cout << a[n] << " " << a[1] << endl; 47 return 0; 48 } 49 } 50 for (int j = 1; j <= n; j += 2) a[j] ^= x; 51 } 52 sort(a + 1, a + 1 + n); 53 cout << a[n] << " " << a[1] << endl; 54 return 0; 55 }