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

5 篇文章 0 订阅

## A. Two Towers

### 2.个人思路：

1.新柱子也是符合条件不存在连续不同的。
2.新柱子只有最初连接的方块颜色相同（eg. rbrbr和rbrbr）合并。

### 3.代码：

ll t, n, m, cnt[100005];
string s1, s2;

int main() {
cin >> t;
while (t--) {
cin >> n >> m;
cin >> s1 >> s2;
int cnt = 0;
string s3 = s1;
for (int i = 0; i < s2.size(); i++) {
s3 += s2[m - i - 1];
}
for (int i = 0; i < s3.size() - 1; i++) {
if (s3[i] == s3[i + 1]) cnt++;
}
cout << ((cnt > 1) ? "NO\n" : "YES\n");
}
return 0;
}


## B、Ideal Point

### 3.代码：

struct com {
ll f;
ll to;
ll u;
bool operator < (const com& b) const {
return f < b.f;
}
};

ll t, n, k;
vector<com> lis;

int main() {
cin >> t;
while (t--) {
cin >> n >> k;
int arr[55] = { 0 };
for (int i = 1; i <= 50; i++) arr[i] = 0;
lis.clear();
int max = 0, mn = 0;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if (a <= k && b >= k) {
lis.push_back({ a, b, 0 });
}
}
for (int i = 0; i < lis.size(); i++) {
int x = lis[i].f, y = lis[i].to;
for (int j = x; j <= y; j++) {
arr[j]++;
}
}
for (int i = 1; i <= 50; i++) {
if (arr[i] > max) {
mn = 1;
max = arr[i];
}
else if (arr[i] == max) {
mn++;
}
}
if (mn == 1 && max == arr[k]) {
cout << "YES\n";
}
else cout << "NO\n";
}

return 0;
}


## C、Tea Tasting

### 3.代码：

struct com {
ll f;
ll to;
ll u;
bool operator < (const com& b) const {
return f < b.f;
}
};

ll t, n, a[200005], b[200005], sum[200005], c[200005], ans[200005], x[200005];
vector<com> lis;

int main() {
cin >> t;
while (t--) {
cin >> n;
c[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c[i] = 0;
ans[i] = 0;
x[i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
sum[i] = sum[i - 1] + b[i];
}
for (int i = 1; i <= n; i++) {
int l = i, r = n, mid = (l + r) >> 1;
while (l < r) {
mid = (l + r) >> 1;
if (a[i] > sum[mid] - sum[i - 1]) {
l = mid + 1;
}
else r = mid;
}
mid = l;
if (sum[mid] - sum[i - 1] > a[i]) {
ans[mid] += a[i] - (sum[mid - 1] - sum[i - 1]);
c[i - 1] += 1;
c[mid - 1] -= 1;
}
else {
c[i - 1] += 1;
c[mid] -= 1;
}
}
for (int i = 1; i <= n; i++) {
x[i] = c[i - 1] + x[i - 1];
ans[i] += x[i] * b[i];
cout << ans[i] << " ";
}
cout << "\n";
}

return 0;
}


## D. Triangle Coloring

### 2.个人思路：

1. 三边相等，随便选，三种可能。
2. 两边相等，第三边大于两边，最优是第三边+任意一边，两种可能。
3. 两边相等，第三边小于于两边，最优是两个相等边，一种可能。
4. 三边不等，一种可能。

### 3.代码：

ll n, ans = 1, p = 998244353;
ll inf[300005], m1[300005];
ll arr[300005];

ll qp(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}

ll cal(int x, int y) {
return (m1[x] * inf[y] % p) * inf[x - y] % p;
}

int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
m1[0] = inf[0] = 1;
for (int i = 1; i <= n / 3; i++) {
m1[i] = m1[i - 1] * i % p;
inf[i] = inf[i - 1] * qp(i, p - 2) % p;
}

for (int i = 1; i <= n / 3; i++) {
int a = arr[i * 3], b = arr[i * 3 - 1], c = arr[i * 3 - 2];
if (a == b && b == c) ans = (ans * 3) % p;
else if (a == b && c > b) ans = (ans * 2) % p;
else if (c == b && a > b) ans = (ans * 2) % p;
else if (a == c && b > c) ans = (ans * 2) % p;
}
cout << (ans * cal(n / 3, n / 6)) % p;
return 0;
}


## E. Explosions?

### 2.个人思路：

1. 消耗轰炸中心的怪物血量无意义
2. 普通魔法只需要用来让序列变成一个以目标为中心向两侧严格递减的序列即可。

dp的转移方程是 dp[i] = dp[a] + [i, a]变成递减序列的代价，也就是求一个
max(arr[i] - i + a, 0)到 arr[i] 的和。

### 3.代码：

ll t, n, arr[300005], sum[300005];
ll gui[300005][2], dp[300005][2];

ll cal(ll x) {
return (x * (x + 1)) / 2;
}

int main() {
cin >> t;
while (t--) {
cin >> n;
ll ans = (ll)1e12;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
sum[i] = sum[i - 1] + arr[i];
gui[i][1] = n + 1;
dp[i][0] = dp[i][1] = 0;
gui[i][0] = 0;
}
dp[n + 1][0] = dp[n + 1][1] = 0;
stack<int> sin[2];
for (int i = n; i > 0; i--) {
//这里的两个取最大值是无效的
while (!sin[0].empty() && (arr[i] <= max(arr[sin[0].top()] - (sin[0].top() - i), 0ll))) {
gui[sin[0].top()][0] = i;
sin[0].pop();
}
sin[0].push(i);
}
for (int i = 1; i <= n; i++) {
while (!sin[1].empty() && (arr[i] <= max(arr[sin[1].top()] - (i - sin[1].top()), 0ll))) {
gui[sin[1].top()][1] = i;
sin[1].pop();
}
sin[1].push(i);
}
for (int i = 1; i <= n; i++) {
int a = gui[i][0], j = n - i + 1, b = gui[j][1];
dp[i][0] = dp[a][0] + (sum[i] - sum[a] - (cal(arr[i]) - cal(max(arr[i] - i + a, 0ll))));
dp[j][1] = dp[b][1] + (sum[b - 1] - sum[j - 1] - (cal(arr[j]) - cal(max(arr[j] - b + j, 0ll))));
}
for (int i = 1; i <= n; i++) {
ans = min(dp[i][0] + dp[i][1] + arr[i], ans);
}
cout << ans << "\n";
}
return 0;
}


## 总结

• 1
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
05-21 167
02-20 332
03-24 591
05-14 564
05-18 493
07-19 176

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

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