# A  Gold and Silver

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

//inline int min(const double x, const double y) {return x < y ? x : y;}
//inline int max(const double x, const double y) {return x > y ? x : y;}

int ans[200005], a[200005], j, lst, n;

int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++ i) scanf("%d", a + i);
for (int i = 1; i <= n; ++ i, j ^= 1) {
if (!j) {
while (i < n && a[i] <= a[i + 1]) ++ i;
ans[i] = 1, lst = i;
} else {
while (i < n && a[i] >= a[i + 1]) ++ i;
ans[i] = 1, lst = i;
}
}
if (j) ans[lst] = 0;
for (int i = 1; i <= n; ++ i) printf("%d ", ans[i]);
return 0;
}
View Code

# B  Balls of Three Colors

1. 将红球和绿球转换成蓝球；

2. 将绿球和蓝球转换成红球；

3. 将绿球和蓝球转换成红球。

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>

inline int min(const int x, const int y) {return x < y ? x : y;}
inline int max(const int x, const int y) {return x > y ? x : y;}
int a[4];

int main() {
int T;
scanf("%d", &T);
while (T --) {
scanf("%d%d%d", a + 1, a + 2, a + 3);
int ans = 1e9;
for (int i = 1; i <= 3; ++ i)
for (int j = i + 1; j <= 3; ++ j)
if (abs(a[i] - a[j]) % 3 == 0) ans = min(ans, max(a[i], a[j]));
printf("%d\n", ans == 1e9 ? -1 : ans);
}
return 0;
}
View Code

# C  Max Dot

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long

inline double min(const double x, const double y) {return x < y ? x : y;}
inline double max(const double x, const double y) {return x > y ? x : y;}
int a[5005], suf[5005], n, m, s, mx;
double sm[5005], ans = 0;

signed main() {
scanf("%lld%lld%lld", &n, &m, &s);
for (int i = 1; i <= n; ++ i) scanf("%lld", a + i);
for (int lp = n; lp && s >= 1e-8;) {
mx = 0;
suf[lp + 1] = 0;
for (int i = lp; i; -- i) suf[i] = suf[i + 1] + a[i];
for (int i = lp; i; -- i) {
suf[i] = suf[i + 1] + a[i];
sm[i] = 1.0 * suf[i] / (lp - i + 1);
if (sm[i] > sm[mx]) mx = i;
}
double tmp = min(1.0 * (lp - mx + 1) * m, s);
ans += tmp * sm[mx], s -= tmp, lp = mx - 1;
}
printf("%.6lf", ans);
return 0;
}
View Code

# D  Neq Neq

$$1,2,3,4$$

$$4,5,6,7,8$$

$$8,9$$

#include <cstdio>
#define int long long

const int mod = 998244353;
int a[200005], b[200005], cnt[200005], dp[200005], sum[200005], l[200005], r[200005], tot;

int solve(int n) {
for (int i = 1; i <= n; ++ i) cnt[b[i]] = dp[i] = 0;
dp[1] = sum[1] = cnt[b[1]] = 1;
for (int i = 2, j = 0, now = 1; i <= n; ++ i) {
if (!cnt[b[i]]) ++ now;
++ cnt[b[i]];
dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
if (now < 3) {sum[i] = (sum[i - 1] + dp[i]) % mod; continue;}
while (now >= 3 && j < i - 3) {
if (!-- cnt[b[j]]) -- now; ++ j;
}
if (now < 3) now = 3, ++ cnt[b[-- j]];
sum[i] = (sum[i - 1] + (dp[i] = (dp[i] + sum[j]) % mod)) % mod;
}
return dp[n];
}

signed main() {
int n, ans = 1;
scanf("%lld", &n);
for (int i = 1; i <= n; ++ i) scanf("%lld", a + i);
int p = 1;
while (p < n && a[1] == a[p + 1]) ++ p;
l[tot = 1] = 1, r[1] = p;
for (int i = p + 1; i <= n; ++ i) {
int j = i;
while (j < n && a[i] == a[j + 1]) ++ j;
if (i != j) l[++ tot] = i, r[tot] = j;
i = j;
}
if (r[tot] != n) ++ tot, l[tot] = r[tot] = n;
for (int i = 1; i < tot; ++ i) {
int len = 0;
for (int j = r[i]; j <= l[i + 1]; ++ j) b[++ len] = a[j];
ans = ans * solve(len) % mod;
}
printf("%lld", ans);
return 0;
}
View Code

posted @ 2021-10-17 14:29  zqs2020  阅读(113)  评论(0编辑  收藏  举报