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;
}