8.29-河西校区
T1
U594492 排队队
思路
模拟题意。
赛时代码&得分
#include <bits/stdc++.h>
using namespace std;
int n;
char c, d;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> d;
for (int i = 1; i < n; i ++) {
cin >> c;
if (c == d) {
cout << "No";
return 0;
}
d = c;
}
cout << "Yes";
return 0;
}T2
U594497 名称称
思路
模拟题意。
赛时代码&得分
#include <bits/stdc++.h>
using namespace std;
char c;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 8; i; i --)
for (int j = 0; j < 8; j ++) {
cin >> c;
if (c == '*')
cout << char(j + 'a') << i;
}
return 0;
}T3
U594502 数列列
思路
存双倍,排序,开桶( map )存这个数 的结果,边找边存
赛时得分
正解
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, x;
map<int, int> b;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
x = abs(x);
if (x == 0) {
cout << "Yes";
return 0;
}
for (int i = 1; i <= n; i ++) {
cin >> a[i];
a[i + n] = a[i];
}
sort(a + 1, a + 1 + n + n);
for (int i = 1; i <= n + n; i ++) {
if (b.count(a[i])) {
cout << "Yes";
return 0;
}
b[a[i] + x] = 1;
}
cout << "No";
return 0;
}T4
T638295 城市列表表
思路
邻接表排序
赛时代码&得分
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, u, v;
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 <= m; i ++) {
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
for (int i = 1; i <= n; i ++) {
sort(G[i].begin(), G[i].end());
int len = G[i].size();
cout << len << " ";
for (int j = 0; j < len; j ++)
cout << G[i][j] << " ";
cout << "\n";
}
return 0;
}T5
U594511 二进制猜猜
思路
dfs + 超级无敌剪枝优化
赛时得分
正解
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, ans = -1, len;
string s;
void dfs(int u, ll b) {
if ((ans != -1) || ((b << (len - u + 1)) > n))
return;
if (u > len) {
ans = b;
return;
}
if (s[u] == '?') {
dfs(u + 1, b * 2 + 1);
dfs(u + 1, b * 2);
} else
dfs(u + 1, b * 2 + (s[u] - '0'));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s >> n;
len = s.size();
s = '@' + s;
dfs(1, 0);
cout << ans;
return 0;
}T6
U594516 优惠券券
思路
贪心暴力+堆(优先队列)优化
赛时得分
正解
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
struct node {
int v, w;
} a[N];
int n, m, id = 1;
ll ans;
ll b[N];
bool cmp(node x, node y) {
if (x.w == y.w)
return x.v > y.v;
return x.w < y.w;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
cin >> b[i];
ans += b[i];
}
for (int i = 1; i <= m; i ++)
cin >> a[i].w;
for (int i = 1; i <= m; i ++)
cin >> a[i].v;
sort(a + 1, a + 1 + m, cmp);
sort(b + 1, b + 1 + n);
priority_queue<ll> q;
for (int i = 1; i <= n; i ++) {
while (id <= m && a[id].w <= b[i]) {
q.push(a[id].v);
id ++;
}
if (!q.empty()) {
ans -= q.top();
q.pop();
}
}
cout << ans;
return 0;
}