Codeforces Round #638 (Div. 2) 题解
Visits: 237
Phoenix and Balance
由于最大的要比其它所有加起来还要大,因此一定是最大的那个带 $\frac n2 -1$ 个最小的。
int n;
inline void solve() {
rd(n);
ll ans = 1 << n;
for (int i = 1; i < (n >> 1); i++) ans += 1 << i;
for (int i = n >> 1; i < n; i++) ans -= 1 << i;
print(ans);
}
int main() {
int T;
rd(T);
while (T--) solve();
return 0;
}
Phoenix and Beauty
直接构造长为 $nk$ 的序列即可。
const int N = 107;
int n, k, a[N];
inline void solve() {
rd(n, k), rda(a, n);
set<int> s;
for (int i = 1; i <= n; i++) s.insert(a[i]);
if ((int)s.size() > k) return print(-1);
int t = *--s.end();
while ((int)s.size() < k) {
if (t == n) t = 0;
s.insert(++t);
}
print(n * k);
for (int i = 1; i <= n; i++)
for (int x : s) print(x, ' ');
prints("");
}
int main() {
int T;
rd(T);
while (T--) solve();
return 0;
}
Phoenix and Distribution
分类贪心一下。
const int N = 1e5 + 7;
int n, k;
char s[N];
inline void solve() {
rd(n, k), rds(s, n);
sort(s + 1, s + n + 1);
printc(s[k]);
if (s[k] == s[1]) {
if (s[k+1] == s[n])
for (int i = k + 1; i <= n; i += k)
printc(s[i]);
else
for (int i = k + 1; i <= n; i++)
printc(s[i]);
}
prints("");
}
int main() {
int T;
rd(T);
while (T--) solve();
return 0;
}
Phoenix and Science
按照 $2^i$ 随便构造一下即可。
int n;
inline void solve() {
rd(n);
int t = 1, o = 1;
multiset<int> s;
while (o + (1 << t) <= n) s.insert(1 << t), o += 1 << t, ++t;
if (o < n) s.insert(n - o);
o = 1;
print(s.size());
for (int x : s)
print(x - o, ' '), o = x;
prints("");
}
int main() {
int T;
rd(T);
while (T--) solve();
return 0;
}
Phoenix and Berries
简单 DP。
const int N = 507;
const ll inf = 1e18;
int n, k, x, y;
ll f[N][N], s, ans;
bool v[N][N];
inline void upd(ll &x, ll y) {
x = max(x, y);
}
int main() {
rd(n, k);
f[0][0] = 0, v[0][0] = 1;
for (int i = 1; i <= n; i++) {
rd(x, y);
for (int j = 0; j < k; j++)
if (v[i-1][j]) {
upd(f[i][(j+x)%k], f[i-1][j] + (j + x) / k + (s - f[i-1][j] * k - j + y) / k);
v[i][(j+x)%k] = 1;
for (int u = 1; u < k; u++)
if (u <= x && k - u <= y)
upd(f[i][(j+x-u)%k], f[i-1][j] + (j + x - u) / k + (s - f[i-1][j] * k - j + y - (k - u)) / k + 1),
v[i][(j+x-u)%k] = 1;
}
s += x + y;
}
for (int i = 0; i < k; i++)
if (v[n][i]) upd(ans, f[n][i]);
print(ans);
return 0;
}
Phoenix and Memory
题目太神仙了,先咕咕咕着。