# 第十四届蓝桥杯 社区打卡 Day6

TralSun 2023-03-09 02:28:26

t1

``````#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 1;
for (int i = 1; i <= 22; ++i) {
n = n * 20 % 7;
}
cout << (6 + n - 1) % 7 + 1;
return 0;
}``````

t2

``````#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
set<int> st;
for (int i = 1; i <= n; ++i) {
string s; cin >> s;
int idx; cin >> idx;
st.insert(idx);
}
for (int x : st) {
cout << x << '\n';
}
return 0;
}``````

t3

``````#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
int k = 1;
while (k * (k + 1) / 2 < n) ++k;
cout << k;
return 0;
}``````

t4

...全文
35 1 打赏 收藏 举报

1 条回复

TralSun 03-09
• 打赏
• 举报

t4 方法二 感谢梗佬！！

``````#include <bits/stdc++.h>
using namespace std;
const int N = 81, M = 100010;
int n, m, lim, ans;

bool check(int r1, int r2, int k, vector<vector<vector<int>>> &minv, vector<vector<vector<int>>> &maxv) {
deque<int> qmax, qmin;
for (int i = 1; i <= m; ++i) {
if (!qmin.empty() && i - qmin.front() + 1 > k) qmin.pop_front();
while (!qmin.empty() && minv[qmin.back()][r1][r2] > minv[i][r1][r2]) qmin.pop_back();
qmin.push_back(i);
if (!qmax.empty() && i - qmax.front() + 1 > k) qmax.pop_front();
while (!qmax.empty() && maxv[qmax.back()][r1][r2] < maxv[i][r1][r2]) qmax.pop_back();
qmax.push_back(i);
if (i >= k && maxv[qmax.front()][r1][r2] - minv[qmin.front()][r1][r2] <= lim) return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
vector<vector<vector<int>>> minv(m + 10, vector<vector<int>>(n + 10, vector<int>(n + 10, 0)));
vector<vector<vector<int>>> maxv(m + 10, vector<vector<int>>(n + 10, vector<int>(n + 10, 0)));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> minv[j][i][i], maxv[j][i][i] = minv[j][i][i];
cin >> lim;
for (int k = 1; k <= m; ++k)
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j) {
maxv[k][i][j] = max(maxv[k][i][j - 1], maxv[k][j][j]);
minv[k][i][j] = min(minv[k][i][j - 1], minv[k][j][j]);
}
for (int r1 = 1; r1 <= n; ++r1) {
for (int r2 = r1; r2 <= n; ++r2) {
int l = 0, r = m;
while (l < r) {
int mid = l + r + 1 >> 1;
if (check(r1, r2, mid, minv, maxv)) l = mid;
else r = mid - 1;
}
ans = max(ans, (r2 - r1 + 1) * l);
}
}
cout << ans;
return 0;
}
``````

3.5w+

2023-03-09 02:28

刷题！