模拟
AC代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> a(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
if (a[0] + a[1] == a[2]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}
模拟
AC代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
int minx = 0, miny = 0, maxx = n, maxy = m;
while (q--) {
int x, y, a;
cin >> x >> y >> a;
if (a == 1) {
minx = max(minx, x);
} else if (a == 2) {
maxx = min(maxx, x);
} else if (a == 3) {
miny = max(miny, y);
} else {
maxy = min(maxy, y);
}
}
int x = maxx - minx, y = maxy - miny;
if (x <= 0 || y <= 0) {
cout << "0\n";
} else {
cout << x * y << '\n';
}
return 0;
}
找不同的边界数即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
int len = s.size();
int ans = 0;
for (int i = 0; i < len; i++) {
if (i > 0 && s[i] != s[i - 1]) {
ans++;
}
}
cout << ans << '\n';
return 0;
}
记录后缀最大值即为未来要卖的价钱,找出售价-进价的最大值,如果有多个不同的方案,则所有的方案里都需要改变,每次变化只需要改变1即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, t;
cin >> n >> t;
t >>= 1;
vector<int> a(n + 1), maxx(n + 1), cnt(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
priority_queue<int, vector<int>, less<int>> q;
maxx[n] = -0x3f3f3f3f;
q.push(a[n]);
for (int i = n - 1; i >= 1; i--) {
maxx[i] = q.top();
q.push(a[i]);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
cnt[i] = maxx[i] - a[i];
}
int max1 = *max_element(cnt.begin(), cnt.end());
if (max1 <= 0) {
cout << 0 << '\n';
} else {
for (int i = 1; i <= n; i++) {
if (cnt[i] == max1) {
ans++;
}
}
cout << ans << '\n';
}
return 0;
}