ABC370
A
link
判断。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
signed main(){
int l,r;
cin >> l >> r;
if(l == 1&&r == 0) cout << "Yes";
else if(l == 0&&r == 1) cout << "No";
else cout << "Invalid";
return 0;
}
B
link
模拟即可。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n;
int a[105][105];
signed main(){
cin >> n;
for(int i = 1;i <= n;++ i){
for(int j = 1;j <= i;++ j){
cin >> a[i][j];
}
}
int w = 1;
for(int i = 1;i <= n;++ i){
if(w >= i) w = a[w][i];
else w = a[i][w];
}
cout << w;
return 0;
}
C
link
先看哪些位置是变大的,哪些位置是变小的,要想连起来更小,靠前的更小才最优,那么先变小的,从前往后变,再变大的,从后往前变。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
char s[105];
char t[105];
int n,x;
vector<int> ed[5];
signed main(){
cin >> s+1 >> t+1;
n = strlen(s+1);
for(int i = 1;i <= n;++ i){
if(t[i] < s[i]) ed[0].push_back(i),x++;
}
for(int i = n;i >= 1;-- i){
if(t[i] > s[i]) ed[1].push_back(i),x++;
}
cout << x << endl;
for(int i = 0;i < ed[0].size();++ i){
int j = ed[0][i];
s[j] = t[j];
cout << s+1 << endl;
}
for(int i = 0;i < ed[1].size();++ i){
int j = ed[1][i];
s[j] = t[j];
cout << s+1 << endl;
}
return 0;
}