A A+B?
解题思路
无
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
const int N = 2e5 + 5;
ll T;
ll a, b;
void solve() {
scanf("%lld+%lld", &a, &b);
cout << a + b << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
T = 1;
cin >> T;
while (T--) solve();
return 0;
}
B Matrix Rotation
解题思路
模拟即可
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
int a[3][3];
void sp() {
int b[3][3];
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
b[i][j] = a[i][j];
}
}
a[1][1] = b[2][1];
a[1][2] = b[1][1];
a[2][1] = b[2][2];
a[2][2] = b[1][2];
}
bool check() {
for (int i = 1; i <= 2; i++) {
if (a[1][i] >= a[2][i]) return 0;
if (a[i][1] >= a[i][2]) return 0;
}
return 1;
}
void solve() {
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
cin >> a[i][j];
}
}
int ok = 0;
for (int i = 0; i < 4; i++) {
sp();
if (check()) ok = 1;
}
if (ok) cy;
else cn;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
T = 1;
cin >> T;
while (T--) solve();
return 0;
}
C Different Differences
解题思路
求差分数组,使数字种类最多,我们先尽可能使差分数字最多,那么直接构造差分1,2,3,4,...
再判断是否在范围内
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll k, n;
ll ans[N];
void solve() {
cin >> k >> n;
int cnt = 1;
ans[1] = 1;
for (int i = 2; i <= k; i++) {
ans[i] = ans[i - 1] + cnt;
cnt++;
}
cnt = n;
for (int i = k; i >= 1; i--) {
if (ans[i] > n || ans[i] >= ans[i + 1]) {
ans[i] = cnt;
cnt--;
} else break;
}
for (int i = 1; i <= k; i++) cout << ans[i] << ' ';
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
T = 1;
cin >> T;
while (T--) solve();
return 0;
}
D Absolute Sorting
解题思路
分类讨论求x的范围区间
参考代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll n, x;
ll a[N];
ll inf = 9999999999999;
void solve() {
ll l = 0, r = inf;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
if (a[i] < a[i + 1]) r = min(r, (a[i] + a[i + 1]) / 2);
if (a[i] > a[i + 1]) l = max(l, (a[i] + a[i + 1] + 1) / 2);
}
if (l > r) l = -1;
cout << l << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
T = 1;
cin >> T;
while (T--) solve();
return 0;
}