第十四届蓝桥杯三月真题刷题训练——第 26 天

目录

第 1 题:玩具

第 2 题:滑雪

第 3 题:abb

第 4 题:小红取数


第 1 题:玩具

思路:贪心

#include<bits/stdc++.h>
#define ll long long 
const int N=1e6+10;
ll a[N],n;
using namespace std;
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)cin>>a[i];
	sort(a,a+n+1);
	ll ans=0;
	for(ll i=n;i>0;i-=2)
	{
		ans+=a[i];
	}
	if(n%2)ans+=a[0];
	cout<<ans<<endl;
}

第 2 题:滑雪

思路:因为n,m的范围很小,所以直接暴力就可以了,注意判断一下不要出界

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=110;
int f[N][N];
struct point {
	int x,y;	
	ll len;		
	bool flag;	
};
ll ans,n,m;
int mov[4][2]= {{1,0},{0,-1},{-1,0},{0,1}};
queue<point>q;
void bfs() {
	ll cnt=0;
	while(!q.empty()) {
		point tem=q.front();
		q.pop();
		for(int i=0; i<4; i++) {
			int dx=tem.x+mov[i][0],dy=tem.y+mov[i][1];
			if(f[dx][dy]<f[tem.x][tem.y]&&dx>=0&&dx<n&&dy>=0&&dy<m) {
				q.push({dx,dy,tem.len+1});
				tem.flag=true;
			}
			if(!tem.flag)cnt=max(cnt,tem.len);
		}
	}
	ans=max(cnt,ans); 
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			cin>>f[i][j];
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			q.push({i,j,1});
			bfs(); 
		}
	}
	cout<<ans<<endl;
}

第 3 题:abb

思路:提前统计好每一个字符出现的次数,每一次往后读取的时候将前一个字符删除

#include<bits/stdc++.h>
#define ll long long
#define init ios::sync_with_stdio(false),cin.tie(0);
using namespace std;
int f[30],n;
string arr;
ll ans;
int main() {
	init   
	cin>>n;
	cin>>arr;
	for(int i=0; i<n; i++) {
		f[arr[i]-'a']++;
	}
	for(int i=0; i<n; i++) {
		for(int j=0; j<26; j++) {
			if(f[j]>=2&&arr[i]-'a'!=j) {
				ans+=(f[j]*(f[j]-1))/2;
			}
		}
		f[arr[i]-'a']--;
	}
	cout<<ans<<endl;
}

第 4 题:小红取数

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是第十四届蓝桥杯Python组真题的部分内容: 一、选择题(每题5分,共40分) 1. 下列哪个不是Python的内置数据类型? A. int B. float C. char D. str 答案:C 2. 下列哪个不是Python的保留字? A. and B. or C. not D. xor 答案:D 3. 下列哪个不是Python的标准模块? A. os B. sys C. math D. timeit 答案:D 4. 下列哪个Python库可以用于科学计算? A. NumPy B. SciPy C. Matplotlib D. All of the above 答案:D 5. 下列哪个Python库可以用于机器学习? A. TensorFlow B. Keras C. PyTorch D. All of the above 答案:D 6. 下列哪个Python库可以用于爬虫? A. Requests B. BeautifulSoup C. Scrapy D. All of the above 答案:D 7. 下列哪个Python库可以用于图像处理? . OpenCV B. Pillow C. Scikit-image D. All of the above 答案:D 8. 下列哪个Python库可以用于游戏开发? A. Pygame B. Panda3D C. PyOpenGL . All of the above 答案:D 二、编程题(每题20分,共60分) 1. 编写一个Python程序,输入一个字符串,将其中的大写字母转换为小写字母,将其中的小写字母转换为大写字母,然后输出转换后的字符串。 2. 编写一个Python程序,输入一个整数n,输出n的阶乘。 3. 编写一个Python程序,输入一个字符串,判断该字符串是否为回文字符串。如果是回文字符串,则输出True,否则输出False。 以上是部分内容,完整的第十四届蓝桥杯Python组真题可以在蓝桥杯官网上找到。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值