codeforces round911 div2

A

签到题,难在读题,不解释。

#include<iostream>

using namespace std;
#define endl '\n'

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = ' ' + s;
    if (s.find("...") != string::npos) {
        cout << 2 << endl;
        return;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '.')cnt++;
    }
    cout << max(cnt, 0) << endl;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
        solve();
}

B

#include<iostream>

using namespace std;
#define endl '\n'
int a, b, c;

void solve() {
    cin >> a >> b >> c;
    if((b-c) % 2==0)cout << 1<<" ";
    else cout<<0<<' ';
    if((a-c) % 2==0)cout << 1<<" ";
    else cout<<0<<' ';
    if((a-b) % 2==0)cout << 1<<endl;
    else cout<<0<<endl;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
        solve();
}

C

树形DP/DFS

#include <iostream>
using namespace std;
constexpr int N = 3e5 + 10;

struct tree {
    int l, r;
} tr[N];
char s[N];
int n, ans;

void dfs(int x, int c) {
    if (tr[x].l == 0 && tr[x].r == 0) {//搜索到根节点就停止搜索
        ans = min(ans, c);
        return ;
    }
    if (tr[x].l != 0)
        dfs(tr[x].l, c + (s[x] != 'L'));
    if (tr[x].r != 0)
        dfs(tr[x].r, c + (s[x] != 'R'));
}

void solve() {
    ans = 1e9;
    cin >> n;
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
        cin >> tr[i].l >> tr[i].r;
    }
    dfs(1, 0);
    cout << ans << endl;
}

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

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值