2025牛客寒假训练营3部分题解(vegetable dog)
1 前言:
前几天刚说今年的寒假训练营变简单了,这次的训练营3马上就给了本蒟蒻当头一棒,导致这次只做出来了6题(doge)
2 题解
A 智乃的博弈游戏
签到题。判断n的奇偶性即可。
void solve()
{
int n;
cin >> n;
if (n % 2 == 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
M 智乃的牛题
签到题。用桶判断指定字符是否出现指定次数即可。
void solve()
{
string s;
cin >> s;
vector<int>a(125,0);
for (int i = 0;i < 125;i++)
{
a[s[i]]++;
}
if (a[99] == 1 && a[100] == 1 && a[101] == 1 && a[110] == 1 && a[111] == 2 && a[114] == 1 && a[119] == 1)
{
cout << "happy new year" << endl;
}
else
cout << "I AK IOI" << endl;
}
F 智乃的捉迷藏
签到题。本题数据很弱,如果找不到规律可以六重循环判断,也可以根据规律判断。
void solve()
{
int n, a, b, c;
cin >> n >> a >> b >> c;
bool judge = false;
for (int x1 = 0; x1 <= n; x1++) {
for (int x2 = 0; x2 <= n - x1; x2++) {
for (int x3 = 0; x3 <= n - x1 - x2; x3++) {
for (int x4 = 0; x4 <= n - x1 - x2 - x3; x4++) {
for (int x5 = 0; x5 <= n - x1 - x2 - x3 - x4; x5++) {
int x6 = n - x1 - x2 - x3 - x4 - x5;
if (x6 >= 0) {
int sum1 = x1 + x2 + x3;
int sum2 = x3 + x4 + x5;
int sum3 = x5 + x6 + x1;
if (sum1 == a && sum2 == b && sum3 == c) {
judge = true;
break;
}
}
}
if (judge) break;
}
if (judge) break;
}
if (judge) break;
}
if (judge) break;
}
if (judge) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void solve1()
{
int n,a,b,c;
cin >> n >> a >> b >> c;
int sum = a + b + c;
if (sum >= n && sum <= 2 * n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
L 智乃的三角遍历
简单题。本题找到规律后手动打表即可。(本蒟蒻有点菜,赛时没有想出优雅的递归写法(哭哭))
void solve()
{
int n;
cin >> n;
int a1[1] = {1};
int a2[2] = {2,3};
int a3[3] = {4,5,6};
int a4[4] = {7,8,9,10};
int a5[5] = {11,12,13,14,15};
int a6[6] = {16,17,18,19,20,21};
int a7[7] = {22,23,24,25,26,27,28};
int a8[8] = {29,30,31,32,33,34,35,36};
if (n == 1)
cout << "1 2 3 1" << endl;
if (n == 2)
cout << "1 3 6 5 4 2 5 3 2 1" << endl;
if (n == 3)
cout << "1 3 6 10 9 8 7 4 8 5 9 6 5 4 2 5 3 2 1" << endl;
if (n == 4)
cout << " 1 3 6 10 15 14 13 12 11 7 12 8 13 9 14 10 9 8 7 4 8 5 9 6 5 4 2 5 3 2 1" << endl;
if (n == 5)
cout << "1 3 6 10 15 21 20 19 18 17 16 11 17 12 18 13 19 14 20 15 14 13 12 11 7 12 8 13 9 14 10 9 8 7 4 8 5 9 6 5 4 2 5 3 2 1" << endl;
if (n == 6)
cout << "1 3 6 10 15 21 28 27 26 25 24 23 22 16 23 17 24 18 25 19 26 20 27 21 20 19 18 17 16 11 17 12 18 13 19 14 20 15 14 13 12 11 7 12 8 13 9 14 10 9 8 7 4 8 5 9 6 5 4 2 5 3 2 1" << endl;
if (n == 7)
cout << "1 3 6 10 15 21 28 36 35 34 33 32 31 30 29 22 30 23 31 24 32 25 33 26 34 27 35 28 27 26 25 24 23 22 16 23 17 24 18 25 19 26 20 27 21 20 19 18 17 16 11 17 12 18 13 19 14 20 15 14 13 12 11 7 12 8 13 9 14 10 9 8 7 4 8 5 9 6 5 4 2 5 3 2 1" << endl;
}
C 智乃的Notepad(easy)
本题的hard版本为多组查询,本蒟蒻只能想到字典树,然后就想不下去了,所以在easy版本的单组查询时发现只需要将字符串按字典序排好,然后遍历一遍,将size累加即可。注意最后要将maxsize处理一下。
string s[100005];
void solve()
{
int n, m, i, j, l, r;
cin >> n >> m;
for (i = 1; i <= n; i++)
{
cin >> s[i];
}
cin >> l >> r;
sort(s + l, s + r + 1);
int cnt = 0;
int maxsize = 0;
for (i = l; i <= r; i++)
{
maxsize = max(maxsize, (int)s[i].size());
if (i == l)
{
cnt += s[i].size();
continue;
}
for (j = 0; j < s[i].size() && j < s[i - 1].size(); j++)
{
if (s[i][j] != s[i - 1][j])
{
break;
}
}
cnt += s[i].size() - j;
cnt += s[i - 1].size() - j;
}
cnt += s[n].size();
cnt -= maxsize;
cout << cnt << endl;
}
E 智乃的小球
简单-中等题。本题由于所有小球的质量,速度都相同,且发生完全弹性碰撞,所以所有小球碰撞后只会改变运动方向,速度不变。所以我们可以认为两小球碰撞后互不影响。
根据此性质,我们可以将小球分为从左往右和从右往左两类,然后二分碰撞时间来判断在该时间是否发生第k次碰撞即可。
(其实本蒟蒻一开始没往二分去想,但是注意到碰撞时间只有整数或者0.5,但是题目却给了精度判断,所以推测出二分时间的解法)
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
int p, v;
cin >> p >> v;
mp[p] = v;
}
double l = 0, r = 1e9 + 7;
double mid;
double e = 1e-7;
while (r - l > e)
{
mid = (l + r) / 2;
if (mid > 1e9)
{
printf("No\n");
return;
}
if (midsearch(mid) >= k)
r = mid;
else
l = mid;
}
mid = (l + r) / 2;
printf("Yes\n");
printf("%.12lf\n", mid);
}
3 总结
我还是太菜了555,是时候加训了喵~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话