# 第十四届蓝桥杯 社区打卡 Day16 半个月来最折磨的一次……

TralSun 2023-03-19 20:09:09

t1

``````#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
int n; cin >> n;
char c = n + 'A' - 1;
cout << c;
return 0;
}

``````

t2

``````#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
string s; cin >> s;
map<char, int> cnt;
int t = 0;
for (int i = 0; i < s.size(); ++i) {
if (++cnt[s[i]] > t) t = cnt[s[i]];
}
for (auto x : cnt) {
if (x.second == t) {
cout << x.first << '\n' << x.second;
return 0;
}
}
return 0;
}

``````

t3

``````#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6 + 10;
int s[N * 2];
int o[N], d[N];
int n;
bool ans[N];

signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> o[i] >> d[i];
}
for (int i = 1; i <= n; i++) {
s[i] = o[i] - d[i];
s[i + n] = s[i];
}
for (int i = 1; i <= 2 * n; i++) {
s[i] += s[i - 1];
}
deque<int>qu;
qu.push_back(2 * n + 1);
for (int i = 2 * n; i >= 1; i--) {
if (qu.size() && qu.front() > i + n - 1) qu.pop_front();
if (i < n) {
if (s[qu.front()] - s[i - 1] >= 0) ans[i] = true;
}
while (qu.size() && s[qu.back()] >= s[i - 1]) qu.pop_back();
qu.push_back(i - 1);
}
d[0] = d[n];
for (int i = 1; i <= n; i++) {
s[i] = o[i] - d[i - 1];
s[i + n] = s[i];
}
for (int i = 1; i <= 2 * n; i++) {
s[i] += s[i - 1];
}
qu.clear();
qu.push_back(0);
for (int i = 0; i <= 2 * n - 1; i++) {
if (qu.size() && qu.front() < i - n + 1) qu.pop_front();
if (i + 1 > n) {
if (s[i + 1] - s[qu.front()] >= 0) ans[i - n + 1] = true;
}
while (qu.size() && s[qu.back()] <= s[i + 1]) qu.pop_back();
qu.push_back(i + 1);
}
for (int i = 1; i <= n; i++) {
if (ans[i]) puts("TAK");
else puts("NIE");
}
}``````

t4

``````#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll n, m, q, p[N], dis[N];

ll find(ll x) {
if (p[x] == x) return x;
int t = p[x];
p[x] = find(p[x]);
dis[x] += dis[t];
return p[x];
}

int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> q;
for (ll i = 1; i <= n; ++i) {
p[i] = i;
}
while (m--) {
ll l, r, s; cin >> l >> r >> s;
ll a = find(l - 1), b = find(r);
if (a != b) {
p[a] = b;
dis[a] = -dis[l - 1] + s + dis[r];
}
}
while (q--) {
ll l, r; cin >> l >> r;
ll a = find(l - 1), b = find(r);
if (a != b) cout << "UNKNOWN\n";
else cout << dis[l - 1] - dis[r] << '\n';
}
return 0;
}``````

...全文
15 回复 打赏 收藏 转发到动态 举报

50,603

• 近7日
• 近30日
• 至今

刷题！