8.21-河西校区
T1
T639096 落落的去养植物
赛时代码&得分
#include <bits/stdc++.h>
using namespace std;
unsigned h, p, i, cnt;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> h;
for (i = 1; p <= h; i *= 2) {
p += i;
cnt ++;
}
cout << cnt;
return 0;
}T2
T638488 数字存储
赛时得分&代码
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
const int b[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4294304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
int n;
l ans = 1;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i <= n; i ++) {
for (int j = 0; j < 30; j ++)
if (i >= b[j] && i < b[j + 1]) {
ans += j + 1;
break;
}
}
cout << ans;
return 0;
}T3
T643658 落落的去的数学题1
赛时得分
正解
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
int a, b, c, cnt;
l x, r = 1;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> a >> b >> c;
cout << b - c + 1;
return 0;
}
T4
T638482 小梦的铁索连环
赛时得分
正解
#include <bits/stdc++.h>
#define _(x,y,z) for (int x = y; x <= z; x ++)
using namespace std;
const int N = 455;
int n, m, u, v, ans;
int a[N];
int p[N][N];
vector<int> g[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= m; i ++) {
cin >> u >> v;
p[v][u] = p[u][v] = 1;
g[u].push_back(v);
}
for (int i = 1; i <= n; i ++) {
ans = max(ans, a[i]);
int sz = g[i].size();
for (int j = 0; j < sz; j ++) {
ans = max(ans, a[i] + a[g[i][j]]);
for (int k = j + 1; k < sz; k ++) {
if (!p[g[i][j]][g[i][k]])
continue;
ans = max(ans, a[i] + a[g[i][j]] + a[g[i][k]]);
for (int h = k + 1; h < sz; h ++) {
if (!p[g[i][h]][g[i][k]] || !p[g[i][h]][g[i][j]])
continue;
ans = max(ans, a[i] + a[g[i][j]] + a[g[i][k]] + a[g[i][h]]);
}
}
}
}
cout << ans;
return 0;
}T5
T638458 忙碌的老师
赛时得分
正解
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
int l, r;
} a[N];
bool cmp(node x, node y) {
return x.l < y.l;
}
int n, ans = 1;
priority_queue<int, vector<int>, greater<int> > q;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i].l >> a[i].r;
sort(a + 1, a + 1 + n, cmp);
q.push(a[1].r);
for (int i = 2; i <= n; i ++)
if (q.top() >= a[i].l) {
q.push(a[i].r);
ans ++;
} else {
q.pop();
q.push(a[i].r);
}
cout << ans;
return 0;
}