Codeforces Round #693 (Div. 3) 补题

  • C题
  • 题意在这里插入图片描述
  • 思路
    dp,要倒着。具体看代码。
  • 代码
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+ 10;
ll a[N];
void solve()
{
    
    
    
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<ll> dp(n);
    for(int i=n-1;i>=0;i--)
    {
    
    
        dp[i]=a[i];
        int j=i+a[i];
        if(j<n)
        dp[i]+=dp[j];
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
}

int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin>>t;
    while (t--)
    {
    
    
        solve();
    }
}

D题

  • 题意
    在这里插入图片描述
  • 思路
  • 在这里插入图片描述
  • 代码
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
    
    
  int n;
  cin >> n;
  vector<int> v(n);
  for (int &e : v) {
    
    
    cin >> e;
  }
  sort(v.rbegin(), v.rend());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    
    
    if (i % 2 == 0) {
    
    
      if (v[i] % 2 == 0) {
    
    
        ans += v[i];
      }
    } else {
    
    
      if (v[i] % 2 == 1) {
    
    
        ans -= v[i];
      }
    }
  }
  if (ans == 0) {
    
    
    cout << "Tie\n";
  } else if (ans > 0) {
    
    
    cout << "Alice\n";
  } else {
    
    
    cout << "Bob\n";
  }
}

int main() {
    
    
  int t;
  cin >> t;
  while (t--) {
    
    
    solve();
  }
  return 0;
}

粘一个大佬题解

猜你喜欢

转载自blog.csdn.net/qq_46264636/article/details/113268166