Atcoder Grand Contest 034 简要题解

Kenken Race

考虑两个人不互相影响的情况,显然只需要判断是否存在两个相邻的障碍即可;

当原来在前面的人要走到后面时,需要存在三个连续的空位来跳过去。

#include <bits/stdc++.h>

using namespace std;

int main() {
   
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  --a;
  --b;
  --c;
  --d;
  auto check = [&](int a, int b) {
   
    for (int i = a; i < b; ++i) {
   
      if (s[i] == '#' && s[i + 1] == '#') {
   
        return false;
      }
    }
    return true;
  };
  if (!check(a, c) || !check(b, d)) {
   
    cout << "No" << "\n";
  } else if (c <= d) {
   
    cout << "Yes" << "\n";
  } else {
   
    for (int i = b; i <= d; ++i) {
   
      if (i - 1 >= 0 && i + 1 < n && s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
   
        cout << "Yes" << "\n";
        return 0;
      }
    }
    cout << "No" << "\n";
  }
  return 0;
}

ABC

可以将一次操作看成将 A A A 往后移,不难发现能移就移是最优的,那么倒着扫一遍维护后面 B C BC BC 的个数即可。

#include <bits/stdc++.h>

using namespace std;

int main() {
   
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  long long ans = 0;
  int stage = 0;
  int back = 0;
  for (auto c : s) {
   
    if (c == 'A') {
   
      if (stage) {
   
        stage = back = 0;
      } else {
   
        ans += back;
      }
    } else if (c == 'B') {
   
      if (stage) {
   
        stage = 0;
        back++;
      } else {
   
        stage = back = 0;
      }
    } else {
   
      if (stage) {
   
        back = 0;
      } else {
   
        stage = 1;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Tests

显然劣势的考试会选择 l l l ,优势的会选择 u u u 。由于贡献的导数是不降的,所以一定是选若干个喂满,至多有一个不喂;二分答案后判断即可。

#include <bits/stdc++.h>

using namespace std;

struct point {
   
  int b, l, u;
  long long s;
  
  bool operator < (const point &other) const {
   
    return s > other.s;
  }
};

int main() {
   
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<point> a(n);
  long long need = 0;
  for (int i = 0; i < n; ++i) {
   
    cin >> a[i].b >> a[i].l >> a[i].u;
    need += (long long) a[i].b * a[i].l;
    a[i].s = (long long) a[i].l * a[i].b + (long 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值