window.cnblogsConfig = {//可以放多张照片,应该是在每一个博文上面的图片,如果是多张的话,那么就随机换的。 homeTopImg: [ "https://cdn.luogu.com.cn/upload/image_hosting/xkzro04i.png" ], }

CSP-J 2023 赛前模拟赛 Day 3 比赛复盘

CSP-J 2023 赛前模拟赛 Day 3 比赛复盘

总分:$100+20+0+0=120$

分析:

T1:

第一题是一道模拟题(我觉得是数学题)。总共提交了 $4$ 次,主要修改了输出和数据类型。原来的输出是电影面积占屏幕面积的几分之几,更改后为空闲面积占屏幕面积的几分之几;而数据类型险些 “不开 long long 见祖宗” $60$ 分。

AC Code:

#include <cstdio>
#include <algorithm>
using namespace std;
using LL = long long;
int main()
{
LL a, b, c, d;
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
LL x = __gcd(a, c), y = __gcd(b, d);
LL la = a * c / x, lb = b * c / x, lc = a * c / x, ld = a * d / x;
LL ra = a * d / y, rb = b * d / y, rc = b * c / y, rd = b * d / y;
if(lc * ld < la * lb && rc * rd < ra * rb)
if(1.0 * lc * ld / la / lb > 1.0 * rc * rd / ra / rb)
printf("%lld/%lld", la * lb / __gcd(lc * ld, la * lb) - lc * ld / __gcd(lc * ld, la * lb), la * lb / __gcd(lc * ld, la * lb));
else if(1.0 * lc * ld / la / lb < 1.0 * rc * rd / ra / rb)
printf("%lld/%lld", ra * rb / __gcd(rc * rd, ra * rb) - rc * rd / __gcd(rc * rd, ra * rb), ra * rb / __gcd(rc * rd, ra * rb));
else
printf("0/1");
else if(lc * ld < la * lb)
printf("%lld/%lld", la * lb / __gcd(lc * ld, la * lb) - lc * ld / __gcd(lc * ld, la * lb), la * lb / __gcd(lc * ld, la * lb));
else if(rc * rd < ra * rb)
printf("%lld/%lld", ra * rb / __gcd(rc * rd, ra * rb) - rc * rd / __gcd(rc * rd, ra * rb), ra * rb / __gcd(rc * rd, ra * rb));
else
printf("0/1");
return 0;
}

T2:

第二题是一道贪心题,但是我的贪心策略是错误的,导致只获得了 $20$ 分 T_T。正确的策略应该是让一个数尽可能的向前交换,因为这样这个数的权值会更大。

AC Code:

#include <iostream>
#include <string>
using namespace std;
string n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for(int k; T--; )
{
cin >> n >> k;
int m = n.size();
for(int i = 0; i < m && k > 0; ++i)
{
int maxn = n[i] - '0', pos = i;
for(int j = i; j <= i + k && j < m; ++j)
if(n[j] - '0' > maxn)
{
maxn = n[j] - '0';
pos = j;
}
n = n.substr(0, i - 0) + n[pos] + n.substr(i, pos - i) + n.substr(pos + 1);
k -= pos - i;
}
cout << n << "\n";
}
return 0;
}

T3:

第三题是一道树的贪心题。我们按照节点的深度和子树大小进行贪心,深度和子树大小的差越大答案越优。

AC Code:

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using LL = long long;
const int N = 200003;
vector<int> G[N];
bool b[N];
int sx[N], uni[N], u[N];
void dfs(const int &p)
{
b[p] = 1;
for(const auto &x: G[p])
if(!b[x])
{
u[x] = u[p] + 1;
dfs(x);
sx[p] += sx[x] + 1;
}
}
int main()
{
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i < n; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
u[1] = 0;
dfs(1);
for(int i = 1; i <= n; ++i)
uni[i] = u[i] - sx[i];
sort(uni + 1, uni + n + 1);
LL ans = 0;
for(int i = n - k + 1; i <= n; ++i)
ans += uni[i];
printf("%lld", ans);
return 0;
}

T4:

第四题正解是贪心+二分,但是 $60$ 分可以用 LIS 获得。先按入口降序排序,然后贪心地选择射线,并二分可能相交的射线。

AC Code:

#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
using PII = pair<int, int>;
const int N = 1000003;
PII a[N];
int c[N], r[N], d[N], len = 0;
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &c[i]);
for(int i = 1; i <= n; ++i)
scanf("%d", &r[i]);
for(int i = 1; i <= n; ++i)
a[c[i]].first = a[r[i]].second = i;
sort(a + 1, a + n + 1, greater<PII>());
d[++len] = a[1].second;
for(int i = 2; i <= n; ++i)
{
int idx = lower_bound(d + 1, d + len + 1, a[i].second) - d;
d[idx] = a[i].second;
if(idx > len)
++len;
}
printf("%d", len);
return 0;
}

总的来说这次的难度比昨天要难一些。

总结:

这次有进步,也有退步。进步是因为第一题 AC 了,退步是因为第二题贪心没想对。相信明天可以考的更好,目标 AK IOI $200$ 分!

签名:

$TigerTanWQY$

日期:

$2023.10.04$


__EOF__

本文作者TigerTanWQY
本文链接https://www.cnblogs.com/TigerTanWQY/p/17988123.html
关于博主:GD-SZ 初一蒟蒻,明年拿下六级勾
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   TigerTanWQY  阅读(17)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示