牛客周赛 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;
}

结语:

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

相关推荐
噜噜噜噜鲁先森1 小时前
STL——String类
开发语言·c++·算法
Severus_black1 小时前
算法题C——用队列实现栈/用栈实现队列
c语言·数据结构·算法·链表
谭欣辰1 小时前
详细讲解 C++ 有向无环图(DAG)及拓扑排序
c++·算法·图论
欧米欧1 小时前
C++算法之双指针算法
开发语言·c++
承渊政道1 小时前
【递归、搜索与回溯算法】(掌握记忆化搜索的核心套路)
数据结构·c++·算法·leetcode·macos·动态规划·宽度优先
REDcker1 小时前
跨平台编译详解 工具链配置与工程化实践
linux·c++·windows·macos·c·跨平台·编译
闻缺陷则喜何志丹2 小时前
【 线性筛 调和级数】P7281 [COCI 2020/2021 #4] Vepar|普及+
c++·算法·洛谷·线性筛·调和级数
zzzsde2 小时前
【Linux】线程概念与控制(1)线程基础与分页式存储管理
linux·运维·服务器·开发语言·算法
穿条秋裤到处跑2 小时前
每日一道leetcode(2026.04.23):等值距离和
算法·leetcode·职场和发展
少许极端2 小时前
算法奇妙屋(四十九)-贡献法
java·算法·leetcode·贡献法