# Educational Codeforces Round 150 (Rated for Div. 2) 感想

5 篇文章 0 订阅

## A、Game with Board

### 3.代码


int main() {
cin >> t;
while (t--) {
cin >> n;
if (n <= 4) {
cout << "Bob\n";
}
else {
cout << "Alice\n";
}
}
return 0;
}


## B、Keep it Beautiful

### 3.代码


ll t, n, m, p = 998244353, k;
ll arr[200005], cz[200005];

int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf_s("%lld", &arr[i]);
}
vector<ll> ans;
ll mn = arr[1], len = 0, stg = 0;
string s;
s += '1';
ans.push_back(arr[1]);
for (int i = 2; i <= n; i++) {
if (arr[i] >= ans[len]) {
if (!stg) {
ans.push_back(arr[i]);
s += '1';
len++;
}
else {
if (arr[i] >= mn && arr[i] <= ans[0]) {
ans.push_back(arr[i]);
s += '1';
len++;
}
else s += '0';
}
}
else if(arr[i] <= ans[0]) {
if (!stg) {
stg = 1;
ans.push_back(arr[i]);
s += '1';
len++;
}
else s += '0';
}
else s += '0';
mn = min(arr[i], mn);
}
cout << s << "\n";
}
return 0;
}


## C、Ranom Numbers

### 2.个人思路

tn保存倒序处理从n到i的表示的数字， mn表示倒叙从n到i的最大值。

nn[i][j]表示到第i位的时候，后面的最大值为j的结果。

### 3.代码

struct com {
ll d;
ll h;
ll p;
bool operator < (const com& b) const {
if (b.d == d && b.h == h) return p < b.p;
if (b.d == d) return h < b.h;
return d < b.d;
}
}lis[300005];

ll t, n, m, p = 998244353;
ll arr[200005], tn[200005], mn[200005];
ll nn[200005][5], sum[200005];
ll pp[5] = { 1, 10, 100, 1000, 10000 };

int main() {
cin >> t;
while (t--) {
string s;
cin >> s;
n = s.size();
ll ans = -2147483647ll * 100000ll;
ll st = 0, tp[5] = {-1, -1, -1, -1, -1};
for (int i = 0; i <= n; i++) {
for (int j = 0; j < 5; j++) {
nn[i][j] = 0;
}
mn[i] = 0;
tn[i] = 0;
sum[i] = 0;
}
for (int i = n - 1; i >= 0; i--) {
mn[i] = max(mn[i + 1], (ll)s[i] - 'A');
if (mn[i] != (s[i] - 'A')) {
tn[i] = tn[i + 1] - pp[s[i] - 'A'];
}
else tn[i] = tn[i + 1] + pp[s[i] - 'A'];
}

for (int i = 0; i < n; i++) {
ll tmp = 0, t1 = 10000, t2 = 0;
for (int j = 0; j < 5; j++) {
ll pos = -1, tar = -1;
for (int k = 0; k < 5; k++) {
if (k >= j) {
if (pos < tp[k]) {
pos = tp[k];
tar = k;
}
}
}
if (pos != -1) {
nn[i][j] = pp[j] - sum[i - 1] + sum[pos] + nn[pos][tar];
}
else nn[i][j] = pp[j] - sum[i - 1];
}
tp[s[i] - 'A'] = i;
if (i > 0) sum[i] = sum[i - 1];
sum[i] += pp[(s[i] - 'A')];
}

for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
ll t1 = max(mn[i + 1], (ll)j);
ans = max(ans, tn[i + 1] + nn[i][t1]);
}
}
cout << ans << "\n";
}
return 0;
}


## D、Pairs of Segments

### 2.个人思路

dp[i] = max(dp[j] + 2, dp[i]);

dp[i] = max(dp[j], dp[i]);


### 3.代码

struct com {
ll d;
ll h;
ll p;
bool operator < (const com& b) const {
if (b.d == d && b.h == h) return p < b.p;
if (b.d == d) return h < b.h;
return d < b.d;
}
}lis[200005], ord[200005];

ll t, n, m, p = 998244353;
vector<ll> gra[2005];
unordered_set<ll> st;
ll dp[2005], mn[2005][2005];

int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> lis[i].d >> lis[i].h;
lis[i].p = i;
ord[i] = { lis[i].h , lis[i].d , lis[i].p };
dp[i] = 0;
mn[i][i + 1] = -1;
}
mn[0][1] = -1;
for (int i = n; i >= 0; i--) {
for (int j = i; j >= 0; j--) {
mn[i][j] = -1;
}
}
sort(ord + 1, ord + 1 + n);
ord[0] = { -1, -1, 0 };
for (int i = n; i > 0; i--) {
for (int j = i; j > 0; j--) {
if (ord[j].d >= ord[i + 1].h) {
mn[i][j] = max(mn[i][j + 1], ord[j].h);
}
else mn[i][j] = mn[i][j + 1];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
if (ord[j].d < mn[i - 1][j + 1] && ord[j].d < ord[i].h) {
dp[i] = max(dp[j] + 2, dp[i]);
}
else {
dp[i] = max(dp[j], dp[i]);
}
}
}
ll ans = 2147483647;
ans = n - dp[n];
cout << ans << "\n";
}
return 0;
}


## E. Fill the Matrix

### 3.代码


ll t, n, m, p = 998244353;
ll arr[200005], tmp[200005], cnt[200005];
unordered_map<ll, ll> le, re;
vector<ll> all[200005];

int main() {
cin >> t;
while (t--) {
scanf_s("%lld", &n);
for (int i = 1; i <= n + 1; i++) {
all[i].clear();
tmp[i] = 0;
cnt[i] = 0;
}
for (int i = 1; i <= n; i++) {
scanf_s("%lld", &arr[i]);
all[arr[i] + 1].push_back(i);
}
cin >> m;
le.clear();
re.clear();
unordered_map<ll, ll> len;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < all[i].size(); j++) {
ll x = all[i][j];
ll ttt = i, i = x;
if (tmp[i - 1] == 0 && tmp[i + 1] == 0) {
le[i] = i;
re[i] = i;
len[1]++;
}
else if (tmp[i - 1] == 1 && tmp[i + 1] == 0) {
ll t1 = re[(ll)i - 1], l = (ll)i - t1;
re.erase((ll)i - 1);
re[i] = t1;
le[t1] = i;
len[l]--;
if (len[l] == 0) len.erase(l);
len[l + 1]++;
}
else if (tmp[i - 1] == 0 && tmp[i + 1] == 1) {
ll t1 = le[(ll)i + 1], l = t1 - i;
le.erase((ll)i + 1);
le[i] = t1;
re[t1] = i;
len[l]--;
if (len[l] == 0) len.erase(l);
len[l + 1]++;
}
else {
ll t2 = le[(ll)i + 1], t1 = re[(ll)i - 1];
ll l1 = (ll)i - t1, l2 = t2 - i;
re.erase((ll)i - 1);
le.erase((ll)i + 1);
le[t1] = t2;
re[t2] = t1;
len[l1]--;
if (len[l1] == 0) len.erase(l1);
len[l2]--;
if (len[l2] == 0) len.erase(l2);
len[t2 - t1 + 1]++;
}
i = ttt;
tmp[x] = 1;
}
for (auto x : len) {
cnt[x.first] += x.second;
}
}
ll ans = m, tt = m;
for (int i = n; i > 0; i--) {
if (!tt) break;
ans -= min(cnt[i], tt / i + (tt % i != 0));
tt -= min(tt, cnt[i] * i);
}
cout << ans << "\n";
}
return 0;
}


## 总结

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
06-30 132
07-31 166
06-13 1933
12-06 1186
08-06 424
08-06 941
08-08 250
08-06 191

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。