【每日一题 | 2025年6.2 ~ 6.8】第16届蓝桥杯部分偏简单题

在这里插入图片描述

个人主页:Guiat
归属专栏:每日一题

在这里插入图片描述

正文

1. 【6.2】P12184 [蓝桥杯 2025 省 Python A] 偏蓝

题目链接:https://www.luogu.com.cn/problem/P12184

【答案】5559680

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
	int ans = 0;
	for (int i = 0; i <= 255; i ++) for (int j = 0; j <= 255; j ++) for (int k = 0; k <= 255; k ++)
	{
		if (k > i && k > j) ans ++;
	}
	cout << ans << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

2. 【6.3】P12156 [蓝桥杯 2025 省 Java B] 电池分组

题目链接:https://www.luogu.com.cn/problem/P12156

【分析】

考察位运算。

① 小蓝需要将这 n 个能量电池分成两组,使得这两组能量电池的能量值异或和相等。

假设可以分成两组(a组和b组)异或和相等 => a组 ^ b组 = sum = 0(自反性)

② 每组至少包含一个能量电池 => n >= 2

以上两个条件即解题的充分必要条件。

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
	int t; cin >> t;
	while (t --)
	{
		int n; cin >> n; int a, sum = 0;
		for (int i = 0; i < n; i ++) cin >> a, sum ^= a;
		if (sum == 0 && n >= 2) cout << "YES\n";
		else cout << "NO\n";
	}
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

3. 【6.4】P12173 [蓝桥杯 2025 省 Python B] 最多次数

题目链接:https://www.luogu.com.cn/problem/P12173

【分析】
考察字符串和贪心。
检查函数:判断当前三个字符是否是‘l’,‘q’,‘b’的任意排列。
整体思路:遍历字符串,每次检查连续的三个字符是否满足喜欢单词,满足将答案加一,跳过三个字符(避免重叠),不满足跳过当前字符继续判断。

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

bool check(char a, char b, char c)
{
	return
	{
		(a == 'l' || a == 'q' || a == 'b') &&
		(b == 'l' || b == 'q' || b == 'b') &&
		(c == 'l' || c == 'q' || c == 'b') &&
		(a != b && a != c && b != c)
	};
}

void solve()
{
	string s; cin >> s; int ans = 0;
	for (int i = 0; i < s.length() - 2; )
	{
		if (check(s[i], s[i + 1], s[i + 2])) ans ++, i += 3;
		else i ++;
	}
	cout << ans << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

4. 【6.5】P12171 [蓝桥杯 2025 省 Python B] 最长字符串

题目链接:https://www.luogu.com.cn/problem/P12171

【分析】
考察字符串。

【答案】afplcu

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
	string s, max_s = "";
	while (cin >> s)
	{
		if (max_s.length() < s.length()) max_s = s;
		else if (max_s.length() == s.length() && max_s > s) max_s = s;
	}
	cout << max_s << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

5.【6.6】P12176 [蓝桥杯 2025 省 Python B] 书架还原

题目链接:https://www.luogu.com.cn/problem/P12176

【分析】

考察贪心 + 并查集。

这道题是说,有一排书编号乱了,我们要把它们摆回正确顺序(编号等于位置),求最少需要交换多少次。

怎么想呢?

举个例子,比如书现在排的是 3 1 2,正确顺序是 1 2 3

我们从左到右看:

  • 第1位是3(不对),那正确应该是1,所以看看1现在在哪(在第2位)。
  • 把第1位的3和第2位的1交换,变成 1 3 2,这时候交换了1次。
  • 接着看第2位是3(不对),正确应该是2,2现在在第3位。
  • 交换第2位和第3位,变成 1 2 3,又交换1次,总共2次。

代码思路:

  • 用数组 a 存当前书的顺序,pos 存每个编号的位置(比如编号3在位置1,pos[3]=1)。
  • 遍历每个位置 i
    • 如果当前书 a[i] 不等于 i(没摆对),就找到编号 i 现在的位置 pos[i]
    • a[i]a[pos[i]] 交换,同时更新它们的位置(因为交换后,这两个编号的位置变了)。
    • 每交换一次,计数器 ans 加1。
  • 最后输出 ans 就是最少交换次数。

为什么这样能行?

因为每次交换至少能让一个书回到正确位置,剩下的书会形成一个“环”(比如3→1→2→3),每个环里的书需要 环长度-1 次交换,这样遍历一遍就能算完所有交换次数,简单又高效!

【AC_Code】

#include <iostream>
#include <utility>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e6 + 10; int a[N], pos[N], ans;

void solve()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i], pos[a[i]] = i;
	for (int i = 1; i <= n; i ++)
	{
		if (a[i] != i) pos[a[i]] = pos[i], swap(a[i], a[pos[i]]), pos[i] = i, ans ++;
	}
	cout << ans << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

6. 【6.7】P12341 [蓝桥杯 2025 省 A/Python B 第二场] 消消乐

题目链接:https://www.luogu.com.cn/problem/P12341

【分析】
考察贪心 + 双指针。
用较前面的A匹配较后面的B,用双指针简单模拟一遍即可!

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
	string s; cin >> s; int l = 0, r = s.size() - 1, ans = s.size();
	while (l < r)
	{
		while (s[l] != 'A' && l < r) l ++;
		while (s[r] != 'B' && l < r) r --;
		if (l < r) ans -= 2, l ++, r --;
	}
	cout << ans << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

7. 【6.8】P12188 [蓝桥杯 2025 省 Java A/研究生组] 变换数组

题目链接:https://www.luogu.com.cn/problem/P12188

【分析】

考察模拟

关键点在于求一个数转为二进制下1的个数,具体见我的代码。

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e3 + 10; int a[N];

//int cal(int num)
//{
//	int cnt = 0;
//	while (num) cnt += num & 1, num >>= 1;
//	return cnt;
//}

void solve()
{
	int n; cin >> n; for (int i = 0; i < n; i ++) cin >> a[i]; int m; cin >> m;
	while (m --) for (int i = 0; i < n; i ++) a[i] *= __builtin_popcount(a[i]);
	// while (m --) for (int i = 0; i < n; i ++) a[i] *= cal(a[i]);
	for (int i = 0; i < n; i ++) cout << a[i] << " \n"[i == n - 1];
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

目 基于附件中的缺陷数据和表3中的订单需求,建立数学模型,制定最优切割方案。 表3:订单的具体切割需求 表格 订单号 订单需求对象 订单量(套) 宽度目标(米) 高度目标(米) 窗框单价(元/套) 1 学校教学楼 120 1.6 2.2 480 2 酒店客房 80 1.8 2.4 680 3 医院病房 60 1.7 2.3 550 4 政府办公楼 40 1.5 2.0 420 说明 (1)利用率 =(总用料量 - 切割后的总余料量)/总用料量,其中总用料量含锯口宽度。 (2中切割损失率及利用率的研究对象是总用料,而非单根原材料。|原材料长度(米)|缺陷位置(米)|缺陷长度(米)|单价(元/根)| | ---- | ---- | ---- | ---- | |5.5|1|0.3|17| |5.5|3|0.2|17.33| |6.2|2|0.4|20.59| |7|1.5|0.2|24.41| |7|4|0.3|24.05| |5.8|1.2|0.5|17.33| |6.5|2.3|0.3|22| |7.5|1|0.6|24.77| |6|2.8|0.4|19.83| |8.2|1.3|0.5|27.64| |6.8|2.1|0.3|23.32| |6.8|5|0.2|23.69| |5.6|1.1|0.2|17.66| |7.3|3.1|0.4|24.77| |6.1|1.7|0.5|19.83| |8|2.5|0.3|27.64| |5.9|3|0.4|18| |6.3|1.9|0.3|21.27| |7.8|1.2|0.4|26.57| |6.7|2.4|0.3|22.91| |5.4|0.8|0.3|16.68| |7.4|3|0.2|25.85| |6.9|2|0.5|22.91| |8.1|2.2|0.4|27.64| |7.6|1.6|0.3|26.2| |5.7|2.7|0.4|17.33| |6.4|1.8|0.2|22| |8.3|0.9|0.3|28.72| |6|1.1|0.5|18| |7.9|2.9|0.2|27.64| |5.5|1.3|0.4|16.68| |6.2|3.2|0.3|20.95| |7.1|2.3|0.5|23.69| |6.8|1.9|0.2|23.69| |5.8|2.5|0.4|17.66| |7.3|3|0.3|25.13| |6.9|2|0.2|24.05| |7.5|1.6|0.4|25.49| |5.6|1|0.3|17.33| |6.4|2.2|0.5|20.95| |6.6|2|0.4|22| |7|3.1|0.3|24.05| |8|1.5|0.2|28| |5.9|1.9|0.3|19.83| |7.7|2.6|0.5|25.85| |6.5|1.1|0.2|22.41| |7.2|2.7|0.4|24.41| |6.1|3|0.3|20.59| |5.4|1.5|0.2|17| |8.2|2|0.5|27.64| |6.7|2.9|0.3|22.91| |7.8|1.2|0.4|26.57| |5.5|2.1|0.5|16.36| |6.6|3.2|0.4|22| |7|1.7|0.3|24.05| |5.8|1|0.4|17.66| |8|2.3|0.2|28| |6.9|2.5|0.3|23.69| |7.2|3|0.4|24.41| |6.3|2.4|0.3|21.27| |8.1|1.9|0.5|27.27| |5.6|3.1|0.4|17| |7.4|2|0.3|25.49| |6.1|1.8|0.5|19.83| |6.8|2.1|0.2|23.69| |7.3|1.4|0.3|25.13| |5.7|2.6|0.4|17.33| |7|2.5|0.2|24.41| |6.5|3|0.3|22| |5.8|1.2|0.5|17.33| |8.2|2.7|0.4|28| |7.5|3|0.3|25.85| |6|1.1|0.3|19.41| |7.7|2.3|0.5|25.85| |6.6|2|0.4|22| |6.2|3.1|0.2|21.27| |7.3|1.5|0.3|25.13| |5.5|2.4|0.4|16.68| |7|1.8|0.5|23.32| |6.9|2.5|0.3|23.69| |8|2.6|0.4|27.27| |7.4|1.7|0.2|25.85| |6.3|3|0.5|20.59|
最新发布
05-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【Air】

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值