Virtual Participation CF1480 (div. 2)

\(\text{A}\) : 两个人轮番从前往后替换字符串中的字符,\(x\) 要字典序最小,\(y\) 要字典序最大,\(x\) 先手,并且修改后的字符不能和原来的字符一样。求最后生成的字符串。

显然题。字典序最小就是 \(a\),字典序最大就是 \(z\)
如果本身就是 \(a\) 就变成 \(b\),如果本来就是 \(z\) 就变成 \(y\)

#include <bits/stdc++.h>
using namespace std;

int t; char ch[100];

int main() {
  cin >> t;
  while (t--) {
    cin >> ch + 1;
    int n = strlen(ch + 1);
    for (int i = 1; i <= n; ++i) {
      if (i&1) {
        if (ch[i] == 'a') ch[i] = 'b';
        else ch[i] = 'a';
      } else {
        if (ch[i] == 'z') ch[i] = 'y';
        else ch[i] = 'z';
      }
    }
    cout << ch+1 << endl;
  }
  return 0;
}

\(\text{B}\) : 一个人打怪兽,攻击力为 \(A\),血量为 \(B\)\(n\) 只怪兽攻击力为 \(x_i\),血量为 \(y_i\),每一回合可以挑怪兽打,双方血量扣掉对方攻击力,判断这个人最后能不能打死所有怪兽。

显然题,特判一下 \(i<n\)\(n\) 的情况分别处理即可。
我不会告诉你我因为没有开 LL 一直 WA。

#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int N = 1e5 + 10;
int t, A, B, n;
struct sb{ int a, b; } x[N];
bool cmp(sb x, sb y) { return x.a<y.a||(x.a==y.a&&x.b<y.b); }
 
inline void solve() {
  scanf("%lld%lld%lld", &A, &B, &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &x[i].a);
  for (int i = 1; i <= n; ++i) scanf("%lld", &x[i].b);
  sort(x+1, x+1+n, cmp);
  for (int i = 1; i <= n; ++i) {
    int ok = (x[i].b % A == 0)? x[i].b/A : x[i].b/A+1;
    B -= ok * x[i].a;
    if (i<n && B<=0) return (void)puts("NO");
    if (i==n && B+x[i].a<=0) return (void)puts("NO");
  }
  puts("YES");
}
 
signed main() {
  scanf("%lld", &t);
  while (t--) solve();
  return 0;
}

\(\text{C}\) : 给一个排列要你猜,你询问不超过 \(100\) 次,求任意一个位置使得 \(a_{i-1}>a_i<a_{i+1}\)

也是显然题(吧)。直接二分就可以了啊,每一次询问 mid 和它左右两个位置的值。
然后往更可能有这样关系的方向走就好了,就是哪边不满足走哪边。

#include <bits/stdc++.h>
using namespace std;

void ask(int x) { cout << "? " << x << endl; }
void print(int x) { cout << "! " << x << endl; }

int main() {
  int n; cin >> n;
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1; ask(mid);
    int L, R, Mid; cin >> Mid;
    if (mid != 1) ask(mid-1), cin >> L; else L = 1919810;
    if (mid != n) ask(mid+1), cin >> R; else R = 1919810;
    if (Mid<L && Mid<R) return print(mid), 0;
    if (L < R) r = mid - 1; else l = mid + 1;
  }
}

\(\text{D1}\) : 要你划分一个序列成两个集合,每个集合将连续相同段合并,求最终集合大小最大和。
显然是个贪心,每一次记录一下上一次选择的颜色然后分情况讨论即可。
这里为了方便正难则反了,用总数减掉合并了的个数。

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n, res, a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n; int lastx = 0, lasty = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    if (a[i] == lastx)
      { if (a[i] == lasty) ++res; else lasty = a[i]; continue; }
    else if (lastx != lasty && lasty != a[i]) lasty = 0;
    lastx = a[i];
  }
  cout << n - res << endl;
  return 0;
}

\(\text{D2}\) : 是 \(\text{D1}\) 变成求最小值的题目。
其实也很显然,只需要继续记录上一次的颜色,最开始类似离散化一下处理即可。

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n, res, idx, idy;
int a[N], siz[N], val[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 0; --i) {
    if (val[a[i]]) siz[i] = val[a[i]];
    else siz[i] = 1919810; val[a[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[idx] == a[i]) idx = i;
    else if (a[idy] == a[i]) idy = i;
    else if (siz[idx] > siz[idy]) ++res, idx = i;
    else ++res, idy = i;
  }
  cout << res << endl;
  return 0;
}
posted @ 2021-10-14 17:01  MistZero  阅读(56)  评论(0编辑  收藏  举报