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

结语:

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

相关推荐
KaMeidebaby11 小时前
卡梅德生物技术快报|PD1 单克隆抗体定制配套 N 糖全谱质控开发
前端·人工智能·算法·数据挖掘·数据分析
8Qi812 小时前
LeetCode 235. 二叉搜索树的最近公共祖先(LCA)
算法·leetcode·二叉树·递归·二叉搜索树·lca·迭代
好评12412 小时前
【C++】智能指针全解
c++·智能指针
bIo7lyA8v12 小时前
算法稳定性分析中的随机扰动建模的技术8
算法
是阿建吖!12 小时前
【Linux】信号
android·linux·c语言·c++
城北徐宫13 小时前
Linux信号深度解剖:5种产生、3张表、4次切换
linux·c++·学习
liulilittle13 小时前
论 Linux 内核态全局稳态带宽的卡尔曼估计与工程实现
linux·服务器·网络·c++·计算机网络·tcp·通信
XBodhi.13 小时前
Visual Studio C++ 语法错误: 缺少“;”(在“return”的前面)
开发语言·c++·visual studio
科研online13 小时前
基于多源数据和XGBoost-SHAP分析中国大陆绿地碳汇空间变异影响因素的非线性相关性与尺度差异
算法·学习方法
Cthy_hy13 小时前
拓扑排序超详解:原理 + Kahn 贪心算法
python·算法·贪心算法