模拟赛
40 + 100 + 100 + 100 = 340
跟cch一样只挂A题:)
这么好的AK的机会qwqwqwqwq
A - 买苹果
我太菜了,连红题都做不出qwq
我太菜了,连红题都做不出qwq
我太菜了,连红题都做不出qwq
我太菜了,连红题都做不出qwq
我太菜了,连红题都做不出qwq
思路都不用脑子,直接贪心的搞就完事了
为什么挂了60呢?
因为没看到“至少”2个字qwq
至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少至少
以后读题先ctrl+f找一下有没有“至少”qwq
不是出题人吃那么多苹果干什么呢,都有1000个了还至少,害我在这么好的日子挂了60分,苹果王吧qwq @出题人 苹果吃多了对身体不好。。
考场写的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, m, a, b;
int main () {
cin >> n >> m >> a >> b;
if (m * a > b) {
cout << n / m * b + (n % m) * a;
} else {
cout << a * n;
}
return 0;
}正确的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, m, a, b;
int main () {
cin >> n >> m >> a >> b;
if (m * a > b) {
cout << min(n / m * b + (n % m) * a, (n / m + 1) * b);
} else {
cout << a * n;
}
return 0;
}差别也不大啊qwq出题人还我AKqwq
B - 平方年
闰年是啥呀
这题是我觉得挂的可能性第二大的,居然没挂:)
先打个平方表,用upper_bound就可以找到下一个平方年。
算天数是最难的,然后wyn脑子忽然一抽就想到了前缀和:),代码难度瞬间就降下来叻:),然后我脑子又一抽想到了从这一年的这个日期到1月1日可以直接枚举,然后就顺利的写完叻:)
我居然一遍过样例了,我心态崩了(又想起小学的时候做这种算日期的数学题没一次对过qwq(这么好的日子肯定要算对啊
又臭又长的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL a, b, c, t[100010];
bool f (LL x) {
if (x % 400 == 0) return 1;
if (x % 100 == 0) return 0;
if (x % 4 == 0) return 1;
return 0;
}
bool ff (LL x) {
if (x <= 7) {
return x & 1;
} else {
return !(x & 1);
}
}
LL get_ans (LL x, LL y, LL z) {
LL ret = (x - 1) * 365;
ret += (x - 1) / 4;
ret -= (x - 1) / 100;
ret += (x - 1) / 400;
for (; y >= 1; y--) {
for (; z >= 1; z--) {
ret++;
}
if (y - 1 == 2) {
if (f(x)) {
z = 29;
} else {
z = 28;
}
} else {
if (ff(y - 1)) {
z = 31;
} else {
z = 30;
}
}
}
return ret;
}
int main () {
for (LL i = 1; i <= 100000; i++) {
t[i] = i * i;
}
cin >> a >> b >> c;
LL tmp = upper_bound(t + 1, t + 100000, a) - t;
tmp = t[tmp];
cout << get_ans(tmp, 1, 1) - get_ans(a, b, c);
return 0;
}C - 满汉全席
这个是我今天觉得挂的概率最低的,果然没挂
(像是说了一句废话:)
(怎么还押韵
看完题:太好了,是我最喜欢的算法!二分yyds!(在这么好的日子遇到这么好的算法(开心:)
就直接二分能做的满汉全席数,然后算一下每个菜需要多少,减掉有的再跟0取max就是需要的钱数,把每个菜需要的钱数加起来跟k比一下就好了:)
又臭又长的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n, k, a[100010], b[100010];
bool check (LL x) {
LL sum = 0;
for (int i = 1; i <= n; i++) {
sum += max(0ll, a[i] * x - b[i]);
}
return sum <= k;
}
int main () {
cin >> n >> k;
LL suma = 0, sumb = k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
suma += a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
sumb += b[i];
}
LL l = 0, r = sumb / suma, ans;
while (l <= r) {
LL mid = l + r >> 1;
if (check(mid)) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans;
return 0;
}所以满汉全席到底是什么
D - 距离一样
我靠我做出第4题叻!!!!!
果然在这么好的日子里彩笔也是有可能AK的吗?
刚看完题直接懵了,怎么T3还很简单,T4就这么难qwq我心态崩了
然后我想到这么好的日子里心态不能崩,心态就又稳了
由于没有思路,我决定先去趟厕所
果然,在厕所里我有了一点头绪 厕所大法好!
一点头绪:如果2个点x、y的lca是它们的中点,那么lca和它的所有祖先,以及它儿子的子树中没有x或y的子树大小的和就是所有跟x、y距离一样的点。
从厕所回机房之后又没思路了qwq
然后我想到,它既然是个无根树,怎么会跟lca有这么大的关系?于是我去厕所想普遍情况。然后真的就在厕所有了最重要的进展!厕所战神实锤
最重要的进展:我先试着想如果中点不是lca(或着想象把刚才都有根树的根弄掉,拍扁是什么样子)然后我发现任意的2个点的所有跟x、y距离一样的点其实是整颗树去掉与它们的中点相连的子树(注意现在没有根!)中,有x或y的那2个。
实现:因为要找中点,所以lca是肯定要求的。求lca我只知道倍增和树链剖分,因为这是模拟赛而且我好久没写树链剖分了,所以我决定想一想树链剖分,然后就想出来了。但是好难写,一堆边界条件qwq(我能考场上写过真是奇迹
超臭超长(刚好100行)的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, sz[100010], fa[100010], d[100010], top[100010], son[100010], q;
vector <int> v[100010];
unordered_map <int, int> mp[100010];
void dfs1 (int x, int f) {
fa[x] = f;
sz[x] = 1;
d[x] = d[f] + 1;
int mx = 0;
for (int i : v[x]) {
if (i == f) continue;
dfs1(i, x);
sz[x] += sz[i];
if (sz[i] > mx) {
mx = sz[i];
son[x] = i;
}
}
}
void dfs2 (int x, int t) {
top[x] = t;
mp[t][d[x]] = x;
if (son[x]) {
dfs2(son[x], t);
}
for (int i : v[x]) {
if (i == son[x] || i == fa[x]) continue;
dfs2(i, i);
}
}
int lca (int x, int y) {
while (top[x] != top[y]) {
if (d[top[x]] > d[top[y]]) {
x = fa[top[x]];
} else {
y = fa[top[y]];
}
}
return d[x] < d[y] ? x : y;
}
int get_ans (int x, int y, int l) {
if (d[x] < d[y]) swap(x, y);
int tmp = d[x] + d[y] - d[l] - d[l], ret = n;
if (tmp & 1) return 0;
tmp /= 2;
tmp = d[x] - tmp;
if (tmp == d[l]) {
while (d[fa[top[x]]] > d[l]) {
x = fa[top[x]];
}
if (d[top[x]] <= d[l]) ret -= sz[son[l]];
else ret -= sz[top[x]];
while (d[fa[top[y]]] > d[l]) {
y = fa[top[y]];
}
if (d[top[y]] <= d[l]) ret -= sz[son[l]];
else ret -= sz[top[y]];
return ret;
}
ret = 0;
while (d[fa[top[x]]] > tmp) {
x = fa[top[x]];
}
if (d[top[x]] > tmp) {
return sz[fa[top[x]]] - sz[top[x]];
}
tmp = mp[top[x]][tmp];
return sz[tmp] - sz[son[tmp]];
}
int main () {
cin >> n;
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
v[x].emplace_back(y);
v[y].emplace_back(x);
}
dfs1(1, 1);
dfs2(1, 1);
for (cin >> q; q--;) {
int x, y;
cin >> x >> y;
if (x == y) {
cout << n << "\n";
continue;
}
int l = lca(x, y);
// cout << l << ' ';
cout << get_ans(x, y, l) << "\n";
}
return 0;
}快写完的时候想起x可能会==y,加了一个特判,后面发现真的有不加这个特判挂了的:)
听讲题的时候学到了没用过但感觉比我之前用的都好用的倍增求lca的jump方式,好耶~:)
搜索
怎么补完模拟赛的题还有时间,那就写一写搜索吧:)
A - 幻形之路
写了1-2h,WA 4发
一看就可以二分啊!
但是我不想写二分:)
3个bfs也是个人物。
第1个bfs:找出从(1,1)不过障碍能到哪些点。
第2个bfs:找出从(n,m)不过障碍能到哪些点。
第3个bfs:把第1个bfs找出的点全部入队,然后找到从这些点到第2个bfs的点的最小距离就是答案。
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t, n, m, f[1010][1010], vis[1010][1010], dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
string s[1010];
void bfs (int xxx, int yyy, int t) {
queue <pair <int, int>> q;
q.push({xxx, yyy});
vis[xxx][yyy] = t;
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 || yy < 1 || xx > n || yy > m || s[xx][yy] == '#' || vis[xx][yy] == t) continue;
vis[xx][yy] = t;
q.push({xx, yy});
}
}
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for (cin >> t; t--;) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = ' ' + s[i];
for (int j = 1; j <= m; j++) {
vis[i][j] = 0;
f[i][j] = 1e9;
}
}
queue <pair <int, int>> q;
bfs(1, 1, 1);
bfs(n, m, 2);
if (vis[1][1] == 2) {
cout << "0\n";
continue;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (vis[i][j] == 1) {
q.push({i, j});
f[i][j] = 0;
}
}
}
while (q.size()) {
int x = q.front().first, y = q.front().second;
q.pop();
if (vis[x][y] == 2) {
cout << f[x][y] - 1 << "\n";
break;
}
for (int i = 0; i < 4; i++) {
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || yy < 1 || xx > n || yy > m) continue;
int v = f[x][y] + 1;
if (f[xx][yy] <= v) continue;
f[xx][yy] = v;
q.push({xx, yy});
}
}
}
return 0;
}B - Fox And Two Dots
写了17分钟,一遍过:)
这么好的日子就该一遍过
直接dfs看有没有环:)
讲题的时候老师说因为没环所以是树,就只需要通过边数判断是不是树就行了qwq感觉智力被碾压qwq
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, m, f[55][55], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
string s[55];
bool dfs (int x, int y, int t) {
f[x][y] = t;
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 || s[xx][yy] != s[x][y]) continue;
if (f[xx][yy] == 0) {
if (dfs(xx, yy, t + 1)) return 1;
} else {
if (t + 1 - f[xx][yy] >= 4) return 1;
}
}
return 0;
}
int main () {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = ' ' + s[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (f[i][j]) continue;
if (dfs(i, j, 1)) {
cout << "Yes";
return 0;
}
}
}
cout << "No";
return 0;
}C - 伤害最大化
写了17分钟,一遍过:)
在这么好的日子里,写题都能飞起来
直接暴力,枚举每个时刻用什么技能:)
还好技能需要冷却,不然我就T了:)
这是个病句吗:若在第 i 个时间刻释放该技能,第 i + 1 个时间刻释放的技能会对一名敌人造成的伤害翻倍。
“会”是不是应该放在“翻倍”前面?
而且如果下一个用累积怒气值的技能,是累积的量翻倍吗?
出题人题意不讲清楚,肯定是吃苹果吃的。
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n, a, d[20], ans;
void dfs (int x, LL sa, int f1, int f2, int f3, int f4, LL qwq, int f) {
if (x == n + 1) {
ans = max(ans, qwq);
return;
}
if (!f1) {
dfs(x + 1, sa, 2, max(0, f2 - 1), max(0, f3 - 1), max(0, f4 - 1), qwq + d[x] + f * d[x], 0);
}
if (!f2) {
dfs(x + 1, sa + a, max(0, f1 - 1), 2, max(0, f3 - 1), max(0, f4 - 1), qwq, 0);
}
if (!f3) {
dfs(x + 1, sa, max(0, f1 - 1), max(0, f2 - 1), 2, max(0, f4 - 1), qwq + sa + f * sa, 0);
}
if (!f4) {
dfs(x + 1, sa, max(0, f1 - 1), max(0, f2 - 1), max(0, f3 - 1), 2, qwq, 1);
}
}
int main () {
cin >> n >> a;
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
dfs(1, 0, 0, 0, 0, 0, 0, 0);
cout << ans;
return 0;
}D - GCD
写了36分钟,一遍过:)
我还以为暴力过不了呢,试了一下才发现,原来在这么好的日子里,评测机也很高兴:)
就直接纯暴力:)
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL t, a, b;
unordered_map <LL, unordered_map <LL, LL>> mp;
LL bfs (LL a, LL b) {
queue <pair <LL, LL>> q;
q.push({a, b});
mp[a][b] = 1;
while (q.size()) {
LL x = q.front().first, y = q.front().second;
q.pop();
LL g = __gcd(x, y);
LL xx = x - g, yy = y - g;
if (!mp[xx][y]) {
q.push({xx, y});
mp[xx][y] = mp[x][y] + 1;
if (xx == 0 && y == 0) return mp[xx][y] - 1;
}
if (!mp[x][yy]) {
q.push({x, yy});
mp[x][yy] = mp[x][y] + 1;
if (x == 0 && yy == 0) return mp[x][yy] - 1;
}
}
}
int main () {
for (cin >> t; t--;) {
cin >> a >> b;
mp.clear();
cout << bfs(a, b) << "\n";
}
return 0;
}后面老师说最多只要26步,为什么!!!
为什么!!! 求大佬解释qwq
写完总结叻:)
有没有发现,我几乎每个题都提到了“这么好的日子”:)
是因为今天是我最喜欢的歌手的出道日:
祝歌手周深出道11周年快乐!