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

结语:

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

相关推荐
寻寻觅觅☆7 小时前
东华OJ-基础题-106-大整数相加(C++)
开发语言·c++·算法
fpcc7 小时前
并行编程实战——CUDA编程的Parallel Task类型
c++·cuda
偷吃的耗子7 小时前
【CNN算法理解】:三、AlexNet 训练模块(附代码)
深度学习·算法·cnn
化学在逃硬闯CS8 小时前
Leetcode1382. 将二叉搜索树变平衡
数据结构·算法
ceclar1238 小时前
C++使用format
开发语言·c++·算法
Gofarlic_OMS9 小时前
科学计算领域MATLAB许可证管理工具对比推荐
运维·开发语言·算法·matlab·自动化
lanhuazui109 小时前
C++ 中什么时候用::(作用域解析运算符)
c++
charlee449 小时前
从零实现一个生产级 RAG 语义搜索系统:C++ + ONNX + FAISS 实战
c++·faiss·onnx·rag·语义搜索
夏鹏今天学习了吗9 小时前
【LeetCode热题100(100/100)】数据流的中位数
算法·leetcode·职场和发展
老约家的可汗9 小时前
初识C++
开发语言·c++