2026素养大赛

· · 个人记录

时间转换大师

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int s;
  cin >> s;

  cout << s / 3600 << ' ' << (s % 3600 / 60) << ' ' << s % 60;
  return 0;
}

奥林匹克评分

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  vector<ll> a(5);
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }  
  sort(a.begin(), a.end());

  ll d;
  cin >> d;
  // accumulate:求和一个区间,0ll表示初始值为longlong类型的0
  cout << d * accumulate(a.begin() + 1, a.end() - 1, 0ll);
  return 0;
}

三角形小路

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int n;
  cin >> n;

  vector<int> a(n + 1), b(n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      ans += 3;
    }
  }

  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] == 1) {
      ans += 3;
    }
  }

  for (int i = 1; i <= n; i++) {
    // 相邻可以减去两条边
    if (a[i] == 1 && a[i - 1] == 1) {
      ans -= 2;
    }
    // 相邻可以减去两条边
    if (b[i] == 1 && b[i - 1] == 1) {
      ans -= 2;
    }
    // 只有奇数情况上下才有公共边,才减2
    if (i % 2 == 1 && a[i] == 1 && b[i] == 1) {
      ans -= 2;
    }
  }
  cout << ans;
  return 0;
}

扫雷

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

int a[505][505];
int mx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int my[] = {0, 1, -1, -1, 1, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int n, m, d;
  cin >> n >> m >> d;

  for (int i = 1; i <= d; i++) {
    int x, y;
    cin >> x >> y;
    a[x][y] = 1;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) {
        cout << "B";
      } else {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          int dx = i + mx[k];
          int dy = j + my[k];
          if (dx >= 1 && dx <= n && dy >= 1 && dy <= m) {
            cnt += a[dx][dy];
          }
        }
        cout << char(cnt + '0');
      }
    }
    cout << endl;
  }
  return 0;
}

气球充气

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  int n;
  cin >> n;

  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  sort(a.begin() + 1, a.end());
  double ans = 1e9;
  for (int i = 1; i <= n; i++) {
    if (a[i] > i) {
      cout << -1;
      return 0;
    }
    ans = min(ans, a[i] * 1.0 / i);
  }

  cout << ans;
  return 0;
}

煮肠粉

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  ll t1, t2, n;
  cin >> t1 >> t2 >> n;

  // a:第一台机器烹饪完的时间
  // b:第二台机器烹饪完的时间
  // c:阿姨准备原材料完的时间
  // ans: 总时间和
  ll a = 0, b = 0, ans = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    ll m = min(a, b);
    // 下一次能准备完材料的时间=同学到达的时间 和 阿姨上次准备完原材料的时间 取最大值
    c = max(c, 1ll * i * i) + t1;
    // 计算 机器烹饪完后的时间 = 准备完材料的时间 和 上一次机器烹饪完的时间 取最大值
    ll t = max(m, c) + t2;

    // 更新最早烹饪完的机器时间
    if (m == a) {
      a = t;
    } else {
      b = t;
    }

    ans += t - 1ll * i * i;
  }
  cout << ans;
  return 0;
}