370
A-C
A
void solve() {
int l, r;cin >> l >> r;
if (l == r) {
cout << "Invalid\n";
} else if (l) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
B
int a[110][110];
void solve() {
int n;cin >> n;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= i;j++) {
cin >> a[i][j];
}
}
int res = a[1][1];
for (int i = 2;i <= n;i++) {
if (i >= res) {
res = a[i][res];
} else {
res = a[res][i];
}
}
cout << res << '\n';
}
C
void solve() {
string s, t;cin >> s >> t;
vector<string> ans;
for (int i = 0;i < s.size();i++) {
if (s[i] != t[i]) {
if (s[i] > t[i]) {
s[i] = t[i];
ans.push_back(s);
}
}
}
for (int i = s.size() - 1;i >= 0;i--) {
if (s[i] != t[i]) {
s[i] = t[i];
ans.push_back(s);
}
}
cout << ans.size() << '\n';
for (auto x : ans)cout << x << '\n';
}
D - Cross Explosion
投放炸弹,若当前位置无炸弹则向四周散开直到遇到没有被炸过的位置为止。求最后剩几个位置没有被炸过
Solution
有想到这种方向,但还是没写出来。
一个新的思路!直接枚举两边的端点然后二分找到相应下标即可。
void solve() {
int n, m, q;cin >> n >> m >> q;
vector<set<int>> g1(n + 1), g2(m + 1);
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
g1[i].insert(j);g2[j].insert(i);
}
}
auto erase = [&](int i, int j) {
g1[i].erase(j);g2[j].erase(i);
};
while (q--) {
int x, y;cin >> x >> y;
if (g1[x].count(y)) {
erase(x, y);continue;
}
// 上
{
auto it = g2[y].lower_bound(x);
if (it != begin(g2[y])) erase(*prev(it), y);
}
// 下
{
auto it = g2[y].lower_bound(x);
if (it != end(g2[y])) erase(*it, y);
}
// 左
{
auto it = g1[x].lower_bound(y);
if (it != begin(g1[x])) erase(x, *prev(it));
}
// 右
{
auto it = g1[x].lower_bound(y);
if (it != end(g1[x])) erase(x, *it);
}
}
int ans = 0;
for (int i = 1;i <= n;i++)ans += g1[i].size();
cout << ans << '\n';
}
后面的题目暂时不管了