2020 年 “联想杯”全国高校程序设计在线邀请赛暨第三届上海理工大学程序设计竞赛
目录
A. Archmage
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t; cin >> t;
while (t--) {
ll n, m, x, y; cin >> n >> m >> x >> y;
if (y >= x) cout << m << endl;
else cout << min(m, (n + (m-1)*y)/x) << endl;
}
return 0;
}
B. Bamboo Leaf Rhapsody
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; scanf("%d",&n);
double ans = 0x3f3f3f3f;
for (int i = 1; i <= n; ++i) {
double x, y, z; scanf("%lf%lf%lf",&x,&y,&z);
ans = min(ans,sqrt(x*x+y*y+z*z));
}
printf("%.3lf\n",ans);
return 0;
}
C. Cheat Sheet
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
set<string> se;
vector<string> ve;
bool cmp(string x, string y) {
return x.size() < y.size();
}
int main() {
int n, m; cin >> n >> m;
for (int i = 1; i <= m; ++i) {
string s; cin >> s;
se.insert(s);
}
for (auto r : se) ve.push_back(r);
sort(ve.begin(),ve.end(),cmp);
int ans = 0;
for (int i = 0; i < ve.size(); ++i) {
n -= ve[i].size();
if (n >= 0) ans++;
n--;
}
cout << ans << endl;
return 0;
}
D. Disaster Recovery
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
struct edge {
int u, v;
};
bool cmp(const edge x, const edge y) {
if (x.v != y.v) return x.v < y.v;
return x.u < y.u;
}
vector<edge> ve;
int n, m;
int fa[maxn], d[maxn];
int find(int x) {
if (fa[x] != x) fa[x] = find(fa[x]);
return fa[x];
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) fa[i] = i;
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v;
if (u > v) swap(u,v);
ve.push_back(edge{u,v});
}
sort(ve.begin(),ve.end(),cmp);
for (int i = 0; i < m; ++i) {
int u = ve[i].u, v = ve[i].v;
int fu = find(u), fv = find(v);
if (fu != fv) {
fa[fu] = fv;
++d[u], ++d[v];
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans = max(ans,d[i]);
}
cout << ans << endl;
return 0;
}
H. Hay Mower
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 505;
const int p = 998244353;
ll r[maxn], c[maxn];
ll a[maxn][maxn];
int main() {
int n, m, k; cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
}
}
while (k--) {
char ch; int xy; ll t;
cin >> ch >> xy >> t;
if (ch == 'r') r[xy] = t;
else c[xy] = t;
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ans = (ans + (max(r[i],c[j])%p)*(a[i][j]%p)%p)%p;
}
}
cout << ans << endl;
return 0;
}
L. Lottery Tickets
#include <bits/stdc++.h>
using namespace std;
int c[10];
int a[] = {00,20,12,32,40,24,44,52,60,16,36,64,56,72,76,80,28,84,68,88,92,96};
int main() {
int t; cin >> t;
while (t--) {
int cnt = 0;
for (int i = 0; i <= 9; ++i) {
cin >> c[i];
cnt += c[i];
}
if (cnt == c[0]) {
cout << 0 << endl;
continue;
}
bool flag = false;
int x, y;
for (int i = 0; i < 22; ++i) {
x = a[i]/10, y = a[i]%10;
if (x == y && c[x] >= 2) {
c[x] -= 2;
flag = true;
break;
}
if (x != y && c[x] >= 1 && c[y] >= 1) {
c[x]--; c[y]--;
flag = true;
break;
}
}
if (flag) {
for (int i = 9; i >= 0; --i) {
while (c[i]--) cout << i;
}
cout << x << y << endl;
continue;
}
if (c[0] >= 1) cout << 0 << endl;
else if (c[4] >= 1) cout << 4 << endl;
else if (c[8] >= 1) cout << 8 << endl;
else cout << -1 << endl;
}
return 0;
}