20260718
一、比赛基本情况
- 比赛日期:20260718
- 比赛时长:3h
- 比赛得分:170
- 比赛排名:20th
二、比赛整体回顾
分数不用说,一如既往的差
时间规划比上次差
三、题目复盘
T1:Drought
- 本题得分:0
- 开始时间:10:10
- 结束时间:11:20
- 总用时:70min
初始思路
考场解题过程
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N];
signed main() {
freopen("drought.in", "r", stdin);
freopen("drought.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
cin >> a[1];
int minn = a[1];
bool flag = true;
for (int i = 2; i <= n; i++)
cin >> a[i], flag = (a[i] == a[1]), minn = min(minn, a[i]);
if (n == 1 || flag) {
cout << "0\n";
continue;
}
int ans = LLONG_MAX;
for (int i = 0; i <= minn; i++) {
int sum = 0;
for (int j = 1; j <= n; j++)
b[i] = a[i];
for (int j = 1; j < n; j++) {
int num1 = b[j] - i, num2 = b[j + 1] - i;
if (b[j] < b[j + 1])
b[j + 1] -= num1, sum += num1 * 2, b[j] = i;
else
b[j] -= num2, sum += num2 * 2, b[j] = i;
}
bool flag = true;
for (int j = 1; j <= n; j++)
if (b[j] != i) {
flag = false;
break;
}
if (flag)
ans = min(ans, sum);
}
if (ans > 1e17)
cout << "-1\n";
else
cout << ans << "\n";
}
return 0;
}赛后题解
补题代码
#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
memset(a, 0x3f, sizeof a);
ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (n == 2) {
cout << (a[1] == a[2] ? 0 : -1) << "\n";
continue;
}
for (int i = 2; i < n; i++) {
if (a[i] > a[i + 1]) {
int t = a[i] - a[i + 1];
a[i - 1] -= t;
a[i] -= t;
ans += t * 2;
}
if (a[i] > a[i - 1]) {
int t = a[i] - a[i - 1];
a[i + 1] -= t;
a[i] -= t;
ans += t * 2;
}
}
for (int i = n - 1; i > 1; i--) {
if (a[i] > a[i + 1]) {
int t = a[i] - a[i + 1];
a[i - 1] -= t;
a[i] -= t;
ans += t * 2;
}
if (a[i] > a[i - 1]) {
int t = a[i] - a[i - 1];
a[i + 1] -= t;
a[i] -= t;
ans += t * 2;
}
}
bool flag = 1;
for (int i = 1; i < n; i++)
if (a[i] != a[i + 1] || a[i] < 0) {
cout << "-1\n";
flag = 0;
break;
}
if (flag)
cout << ans << "\n";
}
return 0;
}复杂度
- 时间复杂度:
本题总结
T2:Non-Transitive Dice
- 本题得分:未编写
- 开始时间:无
- 结束时间:无
- 总用时:无
初始思路
无
考场解题过程
无
考场代码
未编写赛后题解
每个骰子都只有 个面,枚举构造,最后再检查是否合法
补题代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5;
int a[N], b[N], s[N];
bool f(int x[], int y[]) {
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++)
if (x[i] > y[j])
cnt1++;
else if (y[j] > x[i])
cnt2++;
return cnt1 > cnt2;
}
void solve() {
for (int i = 1; i <= 4; i++)
cin >> a[i];
for (int i = 1; i <= 4; i++)
cin >> b[i];
bool flag = 0;
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++)
for (int k = 1; k <= 10; k++) {
if (flag == 1) break;
for (int o = 1; o <= 10; o++) {
if (flag == 1) break;
s[1] = i, s[2] = j, s[3] = k, s[4] = o;
int cnta = f(a, b) + f(a, s);
int cntb = f(b, a) + f(b, s);
int cntc = f(s, a) + f(s, b);
if (cnta == 1 && cntb == 1 && cntc == 1) {
flag = 1;
}
}
}
if (flag == 1) cout << "yes\n";
else cout << "no\n";
}
signed main() {
int t;
cin >> t;
while (t--)
solve();
return 0;
}复杂度
- 时间复杂度:
本题总结
看懂题就很简单了(被T1耽误了555)
T3:Herdle
- 本题得分:100
- 开始时间:8:30
- 结束时间:9:15
- 总用时:45min
初始思路
直接模拟
考场解题过程
通过两个双重循环处理两种高亮
用数组特判每个字母有没有被取过
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
char a[5][5], b[5][5];
bool vis[5][5];
int cnt[200];
signed main() {
freopen("herdle.in", "r", stdin);
freopen("herdle.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
cin >> a[i][j], cnt[a[i][j]]++;
int g = 0;
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) {
cin >> b[i][j];
if (b[i][j] == a[i][j])
g++, vis[i][j] = true, cnt[b[i][j]]--;
}
cout << g << "\n";
int y = 0;
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
if (cnt[b[i][j]] && !vis[i][j])
y++, cnt[b[i][j]]--;
cout << y;
return 0;
}赛后题解
无
复杂度
设
- 时间复杂度:
补题代码
无本题总结
第一时间就想到了直接模拟
T4:Flowerpot S
- 本题得分:70
- 开始时间:9:15
- 结束时间:10:00
- 总用时:45min
初始思路
暴力
考场解题过程
暴力枚举花盆两边的坐标
考场代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
struct node {
int x, y;
} a[N];
bool cmp(node x, node y) {
return x.x < y.x;
}
signed main() {
freopen("fpot.in", "r", stdin);
freopen("fpot.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, d;
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + 1 + n, cmp);
int ans = LLONG_MAX;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
if (abs(a[i].y - a[j].y) >= d)
ans = min(ans, a[j].x - a[i].x);
if (ans > 1e17)
cout << "-1";
else
cout << ans;
return 0;
}赛后题解
这个时间差其实就是 坐标的差值,然后找最大和最小值,所以就要用单调队列
那怎么找花盆的宽度呢?
暴力?太!慢!了!PASS!
所以需要一点技巧:我们用的单调队列对吧,所以至少有一个元素满足要求,它就是——花盆宽度!
- 花盆越大越满足要求
- 所以二分花盆宽度
补题代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, d;
struct node {
int x, y;
} a[N];
bool cmp(node x, node y) {
return x.x < y.x;
}
bool check(int x) {
deque<int> dq1, dq2;
for (int i = 1; i <= n; i++) {
while (dq1.empty() == false && a[i].y >= a[dq1.back()].y)
dq1.pop_back();
dq1.push_back(i);
while (dq1.empty() == false && a[i].x - a[dq1.front()].x > x)
dq1.pop_front();
while (dq2.empty() == false && a[i].y <= a[dq2.back()].y)
dq2.pop_back();
dq2.push_back(i);
while (dq2.empty() == false && a[i].x - a[dq2.front()].x > x)
dq2.pop_front();
if (a[dq1.front()].y - a[dq2.front()].y >= d)
return true;
}
return false;
}
int main() {
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1, cmp);
int l = -1, r = 1e6 + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
if (l == 1e6)
cout << -1;
else
cout << r;
return 0;
}复杂度
- 时间复杂度:
本题总结
当时没有想到正解就打了个暴力
四、整体反思
做得较好的地方
没有因为不仔细丢分
需要改进的地方
时间规划、思维
时间安排总结
T1一直没做出来倒但是就一直做,没有去想T2,有可能当时我去想了T2还能多拿点分