0904dmy模拟赛总结
100 + 20 + 5 + 25 = 150
居然又没挂分!(主要是本来就没什么分可以挂的
A - 剖分
40分钟打完,105分钟才调过,第一次见到这么恶心的
看完题之后有一种树形dp的感觉,但不知道怎么做
于是先把样例画出来手玩一下,发现了一些东西:
- 每条路径的两端都不能有边相连
- 每一个子树的根,要么是从叶子一路连上来,以后再连到顶上,要么是从下面经过它再下去
突然有了一点点感觉,所以先设状态为:
- 可能跟
abs(a - b) 有关系???
然后完全没思路了。不管了,先把送给我的分拿了再说:)
直接枚举
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e5 + 5;
int n, ans1, ans2, mx;
struct aa {
int a, b;
} a[N];
int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].a >> a[i].b;
mx = max({mx, a[i].a, a[i].b});
}
if (n <= 5000 && mx <= 5000) {
mx++;
for (int i = 1, cnt; i <= mx; i++) {
cnt = 0;
for (int j = 1; j <= n; j++) {
if (a[j].a % i < a[j].b % i) {
cnt++;
}
}
ans1 = max(ans1, cnt);
}
for (int i = 1; i <= mx; i++) {
int cnt = 0;
for (int j = 1; j <= n; j++) {
if (a[j].a % i < a[j].b % i) {
cnt++;
}
}
if (cnt == ans1) {
// cout << i << ' ' << cnt << '\n';
ans2 += i;
}
if (i == mx && cnt == ans1) ans2 = -1;
}
cout << ans1 << ' ' << ans2;
return 0;
}
return 0;
}
C - 金币
又送5分!
感觉是
没给这题很多时间,只把送的拿了就走了
因为
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int M = 1e5 + 5, N = 410;
LL m, n, t, a[M], ans;
int main () {
cin >> m >> n >> t;
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
if (n == 0) {
for (int i = 1; i <= m; i++) {
ans += a[i] * t;
}
cout << ans;
return 0;
}
return 0;
}
D - 画图
T4居然还能有
首先是
然后是
其它的想了一下,没搞出来
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e5 + 5;
int n, m, dx[] = {0, 0, 1, -1}, dy[] {1, -1, 0, 0}, fa[N];
struct aa {
int a, l, r;
} a[N];
vector <int> v[N];
void bfs (int x, int y, int z) {
queue <pair <int, int>> q;
q.push({x, y});
int tmp = v[x][y];
v[x][y] = z;
while (q.size()) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
if (v[xx][yy] != tmp) continue;
v[xx][yy] = z;
q.push({xx, yy});
}
}
}
int fd (int x) {
return fa[x] ? fa[x] = fd(fa[x]) : x;
}
int main () {
cin >> n >> m;
if (n != 1) {
for (int i = 1; i <= n; i++) {
v[i].emplace_back(0);
for (int j = 1, x; j <= m; j++) {
cin >> x;
v[i].emplace_back(x);
}
}
int q;
for (cin >> q; q--;) {
int x, y, z;
cin >> x >> y >> z;
if (v[x][y] == z) continue;
bfs(x, y, z);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << v[i][j] << ' ';
}
cout << '\n';
}
return 0;
} else {
n = m;
a[0].a = -1;
for (int i = 1; i <= n; i++) {
cin >> a[i].a;
if (a[i].a == a[i - 1].a) {
fa[i] = fd(i - 1);
a[fa[i]].r = i;
} else {
a[i].l = i;
a[i].r = i;
}
// cout << fd(i) << ' ' << a[fd(i)].a << ' ' << a[fd(i)].l << ' ' << a[fd(i)].r << '\n';
}
int q;
for (cin >> q; q--;) {
int x, y, z;
cin >> x >> y >> z;
x = y;
x = fd(x);
a[x].a = z;
int ll = a[x].l, rr = a[x].r;
if (a[x].l > 1 && a[fd(a[x].l - 1)].a == z) {
ll = a[fd(a[x].l - 1)].l;
fa[x] = fd(a[x].l - 1);
x = fa[x];
a[x].r = rr;
}
if (a[x].r < n && a[fd(a[x].r + 1)].a == z) {
fa[x] = fd(a[x].r + 1);
x = fa[x];
a[x].l = ll;
}
}
for (int i = 1; i <= n; i++) {
cout << a[fd(i)].a << ' ';
}
return 0;
}
return 0;
}
我丢我bfs和并查集这么点东西居然写了快100行。。。
虽然T1调太久(2h才开始看T2),但还好调出来了,T2T3都送了分,出题人爸爸我爱你:)
(上一个总结还说出题人死掉了来着
据说下一场是S的模拟(但这两场虽然是noip也写的S)也就是说,下一场写的会是J模拟吗:)
如果J的模拟上不了300是不是就没救了:)
然而100都没上:)