题解 | 牛客小白月赛88
A题 : 超级闪光牛可乐
点:不会出现输出-1的情况,直接逮一个输出1000次即可
void solve() {
int x; cin >> x;
int n; cin >> n;
int val; char c;
while (n -- ) {
cin >> c >> val;
}
for (int i = 1; i <= 1000; i ++ ) cout << c;
cout << endl;
}
B题 : 人列计算机
点: getline进行输入
#include <bits/stdc++.h>
using namespace std;
int main() {
string a[6];
for (int i = 1; i <= 5; i ++ ) getline(cin, a[i]);
int v1 = a[2][0] - '0', v2 = a[4][0] - '0', v3 = a[3][0] - '0';
if (a[3][5] == 38) {
cout << (v1 & v2) << endl;
}else if (a[3][5] == '=') {
cout << (v1 | v2) << endl;
}else {
cout << !v3 << endl;
}
return 0;
}
C题 : 时间管理大师
点:全化成分钟
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
set<int> s;
while (n -- ) {
int h, m;
cin >> h >> m;
int now = h * 60 + m;
s.insert(now - 1), s.insert(now - 3), s.insert(now - 5);
}
cout << s.size() << endl;
for (int t : s) cout << t / 60 << ' ' << t % 60 << endl;
return 0;
}
D题 : 我不是大富翁
点: 背包
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int st[N], backup[N];
int main() {
int n, m; cin >> n >> m;
st[1] = backup[1] = 1;
for (int i = 1; i <= m; i ++ ) {
int t; cin >> t;
t %= n;
for (int j = 1; j <= n; j ++ ) {
if (st[j] == i) {
int x, y;
x = j - t;
while (x < 1) x += n;
y = j + t;
while (y > n) y -= n;
backup[x] = backup[y] = i + 1;
}
}
memcpy(st, backup, sizeof st);
}
if (st[1] == m + 1) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
E题 : 多重映射
点: 正难则反
#include <bits/stdc++.h>
using namespace std;
inline void solve() {
int n, m; cin >> n >> m;
vector<int> in(n), l(n), r(n);
map<int, int> fa;
for (int i = 0; i < n; i ++ ) cin >> in[i];
for (int i = 0; i < m; i ++ ) cin >> l[i] >> r[i];
for (int i = m - 1; i >= 0; i -- ) {
if (fa.count(r[i])) {
fa[l[i]] = fa[r[i]];
}else {
fa[l[i]] = r[i];
}
}
for (int i = 0; i < n; i ++ ) {
cout << (fa[in[i]] ? fa[in[i]] : in[i]) << " \n"[i == n - 1];
}
}
int main() {
int _; cin >> _;
while (_ -- ) solve();
return 0;
}