# 第十四届蓝桥杯三月真题刷题训练——第 16 天 （3.19）

Cauchy 2023-03-19 21:05:36
``````#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
cout << (char)(n + 'A' - 1) << endl;
return 0;
}``````
``````#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
// 请在此输入您的代码
int count[26]={0},max=0,i;
char ch;
while((ch=getchar())!='\n')
count[ch-'a']++;
for(i=1;i<26;i++)
if(count[i]>count[max])
max=i;
printf("%c\n%d",max+'a',count[max]);
return 0;
}``````
``````#include<bits/stdc++.h>
// #include <bits/extc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define sz size()
#define se second
#define endl ('\n')
#define pb push_back
#define ll long long
#define Int __int128
#define int long long
#define skip continue
#define vi vector<int>
#define eb emplace_back
#define lowbit(x) (x & -x)
#define PII pair<int, int>
#define pqu priority_queue<int>
#define vii vector<vector<int>>
#define vII vector<pair<int,int>>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pql priority_queue<int,vi,greater<int>>
#define Rep(i,a,n) for(int i = (n); i >= (a); --i)
#define rep(i,a,n) for(int i = (a); i <= (n); ++i)
#define lb(v,x) (lower_bound(all(v),x)-(v).begin())
#define ub(v,x) (upper_bound(all(v),x)-(v).begin())
#define Dbug(x) (cout << #x << " <=> " << x << endl)
#define IOS cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
#define print(x,s,e) { rep(i,s,e) cout << x[i] << ' '; cout << endl; }

const int N = 250010, M = N << 2;
const int mod = 1000000007; // 998244353;

using namespace std;
using namespace __gnu_pbds;

/*---------------------------------------------------------------------------------------------------------------------------*/
#ifdef int
#define VALUE_MAX LLONG_MAX
#else
#define VALUE_MAX LONG_MAX
#endif
// #define TIME_TEST_PROGRAM
mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
int rnd(int n = VALUE_MAX) { uniform_int_distribution<int> uid(0, n - 1); return uid(rng); }
/*---------------------------------------------------------------------------------------------------------------------------*/
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*---------------------------------------------------------------------------------------------------------------------------*/
class BIT {
public:
BIT() { memset(tr, 0, sizeof tr); }
int tr[N];
void add(int x, int v = 1) { for (; x < N; x += x & -x) tr[x] += v; }
int sum(int x) { int res = 0; for (; x; x -= x & -x) res += tr[x]; return res; }
}; // 切记用 BIT tr; tr.add(); tr.sum();
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b){ if (!b) { return a; } return gcd(b, a % b); }
ll lcm(ll a, ll b){ return (a * (b / gcd(a, b))); }
ll qmi(ll a, ll b){ if (!b) return 1; if(b & 1) return a * qmi(a * a % mod, b >> 1) % mod; return qmi(a * a % mod, b >> 1) % mod; }
/*---------------------------------------------------------------------------------------------------------------------------*/
// mem(h)
int h[N], w[M], e[M], ne[M], idx; void add(int a, int b, int c = 1) { e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++; }

int n, m, q;
bool st[N];
int fa[N];
int dis[N];

int find(int x) {
return fa[x] = fa[x] == x ? x : find(fa[x]);
}

void bfs(int u) {
queue<int> q;
q.push(u);
st[u] = true;
dis[u] = 0;
while (q.sz) {
auto c = q.front(); q.pop();
for (int i = h[c]; ~i; i = ne[i]) {
int j = e[i];
if (st[j]) continue;
st[j] = true;
dis[j] = dis[c] + w[i];
q.push(j);
}
}
}

void solve() {
memset(h, -1, sizeof h);
cin >> n >> m >> q;
for (int i = 0; i <= n; i++) fa[i] = i;
for (int i = 0; i < m; i++) {
int l, r, s; cin >> l >> r >> s;
fa[find(l - 1)] = find(r);
}
for (int i = 0; i <= n; i++) {
if (!st[i]) bfs(i);
}
for (int i = 1; i <= q; i++) {
int l, r; cin >> l >> r;
if (find(l - 1) != find(r)) {
cout << "UNKNOWN" << endl;
} else {
cout << dis[r] - dis[l - 1] << endl;
}
}
}

signed main() {
#ifdef TIME_TEST_PROGRAM
auto start_time = std::chrono::high_resolution_clock::now();
#endif
IOS int _ = 1;
// cin >> _;
while(_--) { solve(); }

#ifdef TIME_TEST_PROGRAM
auto end_time = std::chrono::high_resolution_clock::now();
cout << "Execution time: [ " << std::chrono::duration_cast<chrono::milliseconds>(
end_time - start_time).count() << " ms ]" << endl;
#endif
return 0;
}``````

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

50,781

• 近7日
• 近30日
• 至今

刷题！