所有题目链接:Dashboard - The 2023 CCPC (Qinhuangdao) Onsite (The 2nd Universal Cup. Stage 9: Qinhuangdao) - Codeforces
中文题面:
contest-37054-zh.pdf (codeforces.com)
G. Path
链接:
Problem - G - Codeforces
中文题面
测试点1
无论哪种方法计算差值和,答案都是11
测试点2
同样无论哪种方法结果都是12
所以我们大胆猜测,我们只需要统计蓝色箭头和红色箭头其中一个的差值和即使答案,在以下代码中,计算的是红色箭头的方法计算出来的答案
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
ll a[N],b[N],ans1[N],ans2[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n,m; cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
ll ans = 0;
for(int i = 1; i <= m; i++) {
ans1[i] = b[i] + a[1];
if(i >= 2) ans += abs(ans1[i] - ans1[i - 1]);
}
for(int i = 1; i <= n; i++){
ans2[i] = a[i] + b[n];
if(i >= 2) ans += abs(ans2[i] - ans2[i - 1]);
}
cout << ans <<'\n';
return 0;
}
A. Make SYSU Great Again I
链接:
Problem - A - Codeforces
中文题面:
找规律即可
#include<bits/stdc++.h>
using namespace std;
int n, k;
map<pair<int, int>, bool> mp;
int main() {
cin >> n >> k;
int x = 1, y = 1;
int idx = 0;
for (int i = 1; i <= k; i++) {
cout << x << " " << y << "\n";
mp[{x, y}] = true;
if (x == n && y == n) {
cout << n << " " << 1 << "\n";
mp[{n, 1}] = true;
idx = i + 2;
break;
}
if (i % 2 == 1) y++;
else x++;
}
x = 1, y = 1;
for (int i = idx; i <= k; i++) {
if (!mp[{x, y}]) {
cout << x << " " << y << "\n";
mp[{x, y}] = true;
y++;
if (y > n) {
x++;
y = 1;
}
continue;
}
while (mp[{x, y}]) {
y++;
if (y > n) {
x++;
y = 1;
}
}
cout << x << " " << y << "\n";
mp[{x, y}] = true;
}
return 0;
}