牛客周赛 Round 130训练

目录

A.红美铃的访客登记

题意分析:

代码实现:

B.爱丽丝的魔力零件分类

题意分析:

代码实现:

C.博丽大结界的稳定轴心

题意分析:

代码实现:

D.魔法人偶的十进制校准

题意分析:

代码实现:

E.爱丽丝的人偶圆舞曲

题意分析:

代码实现:

结语:


A.红美铃的访客登记

题目链接:A-红美铃的访客登记_牛客周赛 Round 130

题意分析:

直接按题意模拟就行了

代码实现:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin >> s;
	ll i=0;
	while (s[i] == '0') i++;
	cout << s.substr(i, s.size()) << endl;
	return 0;
}

B.爱丽丝的魔力零件分类

题目链接:B-爱丽丝的魔力零件分类_牛客周赛 Round 130

题意分析:

我们可以根据多种点的坐标规律得到,符合L形的,四个点的纵坐标之和和横坐标之和分别都为奇数,当时我发现以为过不了,没想到AC了。

代码实现:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
void solve()
{
	int n;
	cin >> n;
	int x = 0, y = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			char c;
			cin >> c;
			if (c == '*')
			{
				x += i, y += j;
			}
		}
	}
	if (x % 2 == 1 && y % 2 == 1)
	{
		cout << "L" << endl;
	}
	else {
		cout << "T" << endl;
	}
}
int main()
{
	int t = 0;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

C.博丽大结界的稳定轴心

题目链接:C-博丽大结界的稳定轴心_牛客周赛 Round 130

题意分析:

我们可以去分析一下二叉树的特点,是不是最多的节点数在3个以下,且这个3个的节点不会作为轴心点。

两个的和一个的都可以作为轴心点。

所有我们可以去先判断到底哪个最大的点数有多大。大于3就直接是零,小于的3就可以作为轴心点。

代码实现:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
void solve()
{
	int n;
	cin >> n;
	int ans = 0;
	vector<int> op(n + 1, 0);
	for (int i = 0; i < n-1; i++)
	{
		int a, b;
		cin >> a >> b;
		op[a]++;
		op[b]++;
	}
	for (auto i : op)
	{
		if (i != 0 && i < 3)
		{
			ans++;
		}
		 if (i > 3)
		{
			cout << 0 << endl;
			return;
		}
	}
	cout << ans << endl;
}
int main()
{
	
		solve();
	
	return 0;
}

D.魔法人偶的十进制校准

题目链接:D-魔法人偶的十进制校准_牛客周赛 Round 130

题意分析:

根据数学原理,我们可以固定分母为11,对于分数x/11 (1≤x≤10):小数展开是循环小数,循环节长度为 2

例如:

6/11 = 0.545454...循环节 "54":5+4=9,5=6-1,4=10-6,奇数位是 5,偶数位是 4

特殊情况处理:当 b=9 时:奇数位公式得到 x=10,10/11=0.909090... 第奇数位是 9 ✓

当 b=0 时:偶数位公式得到 x=10,10/11=0.909090... 第偶数位是 0 ✓

代码实现:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
void solve()
{
	int a, b;
	cin >> a >> b;
	cout << (a % 2 ?  b + 1: 10 - b) << " " <<11<< endl;
}
int main()
{
	int t = 0;
	cin >> t;
	while(t--)
		solve();
	
	return 0;
}

E.爱丽丝的人偶圆舞曲

题目链接:E-爱丽丝的人偶圆舞曲_牛客周赛 Round 130

题意分析:

这个题要采用dp思想,最小修改次数 = 字符串长度 - 最大保留字符数

可以先枚举所有可能的 d(0到25,但对称性只需到13 ),然后对每个 d,计算在保持和谐条件下最多能保留多少原字符,再取所有 d 中的最大值

代码实现:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
int dp[26],da[26];
void solve()
{
	string s;
	cin >> s;
	int m = 0;
	for (int d = 0; d <= 13; d++)
	{
		for (int i = 0; i < 26; i++)
		{
			dp[i] = s[0] - 'a' == i;
		}
		for (int i = 1; i < s.size(); i++)
		{
			for (int j = 0; j < 26; j++)
			{
				da[j] = max(dp[(j - d + 26) % 26], dp[(j + d) % 26]) + (j == s[i] - 'a');
			}
			for (int j = 0; j < 26; j++)
			{
				dp[j] = da[j];
			}
		}
		for (int i = 0; i < 26; i++)
			m = max(m, dp[i]);
	}
	cout << s.size() - m << endl;
}
int main()
{
	
		solve();
	
	return 0;
}

结语:

今天的题解就到这,谢谢观看呀,希望对你们有帮助,有不对的欢迎大家在评论区指出!

相关推荐
DpHard3 分钟前
现代 C++ 中 push 接口为何提供 const T& 与 T&& 两个重载
c++
U-52184F6923 分钟前
深入理解“隐式共享”与“写时复制”:从性能魔法到内存深坑
java·数据库·算法
pp起床43 分钟前
Part02:基本概念以及基本要素
大数据·人工智能·算法
lzh200409191 小时前
红黑树详解
算法
U-52184F691 小时前
深度解析:从 Qt 的 Q_D 宏说起,C++ 工业级 SDK 是如何保证 ABI 稳定性的
数据库·c++·qt
迈巴赫车主1 小时前
蓝桥杯20560逃离高塔
java·开发语言·数据结构·算法·职场和发展·蓝桥杯
泯仲1 小时前
Ragent项目7种设计模式深度解析:从源码看设计模式落地实践
java·算法·设计模式·agent
dulu~dulu1 小时前
算法---寻找和为K的子数组
笔记·python·算法·leetcode
moonsea02031 小时前
【无标题】
算法
佑白雪乐2 小时前
<ACM进度212题>[2026-3-1,2026-3-26]
算法·leetcode