都是些简单题,但我看网上好像没有全题解,写一篇造福大学生。
未初始化警告
签到
#include <iostream>
#include <cstdio>
using namespace std;
#define N 100005
int n, k, ans = 0;
bool vis[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
vis[0] = true;
for(int i = 1; i <= k; ++i) {
int x, y;
cin >> x >> y;
if(!vis[y]) ++ans;
vis[x] = true;
}
cout << ans;
return 0;
}
出行计划
签到
#include <iostream>
#include <cstdio>
using namespace std;
#define N 400005
int n, m, k;
int d[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
int t, c;
cin >> t >> c;
int left = max(1, t - c + 1);
++d[left], --d[t + 1];
}
for(int i = 1; i <= N - 5; ++i) d[i] += d[i - 1];
for(int i = 1; i <= m; ++i) {
int q;
cin >> q;
cout << d[q + k] << endl;
}
return 0;
}
计算资源调度器
简单模拟
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define N 3005
int n, m, g;
int f[N], a[N], na[N], pa[N], paa[N];
bool paar[N];
struct node {
int cnt, l, id;
bool operator <(const node &x) const {
return cnt == x.cnt ? id < x.id : cnt < x.cnt;
}
}nd[N], p[N];
vector < int > seg[N], task[N];
bool used[N], tmp[N];
void nodeFrd(int na) {
for(int i = 0; i < seg[na].size(); ++i) {
int u = seg[na][i];
used[u] = false;
}
for(int i = 1; i <= n