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

结语:

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

相关推荐
Byron Loong29 分钟前
【c++】为什么有了dll和.h,还需要包含lib
java·开发语言·c++
Dlrb121142 分钟前
C语言-指针数组与数组指针
c语言·数据结构·算法·指针·数组指针·指针数组·二级指针
WL_Aurora44 分钟前
Python 算法基础篇之集合
python·算法
坚果派·白晓明1 小时前
【鸿蒙PC三方库移植适配框架解读系列】第一篇:Lycium C/C++ 三方库适配 — 概述与环境配置
c语言·开发语言·c++·harmonyos·开源鸿蒙·三方库·c/c++三方库
平行侠1 小时前
A15 工业路由器IP前缀高速检索与内存压缩系统
网络·tcp/ip·算法
咩咦2 小时前
C++学习笔记02:cin 和 cout 输入输出
c++·学习笔记·cin·输入输出·cout
咩咦2 小时前
C++学习笔记05:引用和常引用
c++·学习笔记·引用·const·常引用
香蕉鼠片2 小时前
算法过程中不会的
开发语言·c++
阿旭超级学得完2 小时前
C++11包装器(function和bind)
java·开发语言·c++·算法·哈希算法·散列表
li星野2 小时前
位运算 & 数学 & 高频进阶九题通关(Python + C++)
c++·python·学习·算法