/* * @题目: C - One More aab aba baa * @算法: 全排列问题 * @Author: Blore * @Language: c++11 * @Date: 2021-08-21 20:21:14 * @LastEditors: Blore * @LastEditTime: 2021-08-21 20:26:00 */ #include<bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define maxn 200010 #define maxm 200010 #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, r, l) for (int i = r; i >= l; i--) #define ll long long usingnamespace std; constint inf = 0x7fffffff; intread() { int p = 0, f = 1; char c = getchar(); while (c < 48 || c > 57) { if (c == '-') f = -1; c = getchar(); } while (c >= 48 && c <= 57) p = (p << 1) + (p << 3) + (c ^ 48), c = getchar(); return p * f; } char tmp[10];
intmain() { cin >> tmp; int n = strlen(tmp), m = read(); sort(tmp, tmp + n); int cnt = 0;
do { cnt++; if (cnt == m) break; } while (next_permutation(tmp, tmp + n)); cout << tmp; return0; }
D - Coprime 2
题面
给定含$N$个正整数的数组A,枚举所有$k(1 \le k \le M)$使得$\gcd(A_i,k)=1,1 \le i \le N$
/* * @题目: F - Dist Max 2 * @算法: 二分 * @Author: Blore * @Language: c++11 * @Date: 2021-08-22 16:11:38 * @LastEditors: Blore * @LastEditTime: 2021-08-22 16:23:43 */ #include<bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define maxn 200010 #define maxm 200010 #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, r, l) for (int i = r; i >= l; i--) #define ll long long usingnamespace std; constint inf = 1e9 + 1; intread() { int p = 0, f = 1; char c = getchar(); while (c < 48 || c > 57) { if (c == '-') f = -1; c = getchar(); } while (c >= 48 && c <= 57) p = (p << 1) + (p << 3) + (c ^ 48), c = getchar(); return p * f; } vector<pair<int, int>> a; boolcheck(int k) { queue<pair<int, int>> q; int mi = inf, ma = 0; for (int i = 0; i < a.size(); i++) { while (!q.empty()) { if (q.front().first > a[i].first - k) break; mi = min(mi, q.front().second), ma = max(ma, q.front().second); q.pop(); } if (mi <= a[i].second - k || ma >= a[i].second + k) return1; q.push(a[i]); } return0; } intmain() { int n = read(); rep(i, 1, n) { int x = read(), y = read(); a.pb(mp(x, y)); } sort(a.begin(), a.end()); int l = 0, r = inf; while (r - l > 1) { int m = (l + r) >> 1; if (check(m)) l = m; else r = m; } printf("%d", l); return0; }