2024 ccpc--BFJ题

首先这次比赛在赛场中我们完全可以将BFJ三道题写出来

B题 扫雷

注意,题目要求最多可买几个,那我们完全可以用尽量多的扫雷币去买价格小的地雷

最简单的方法,从后往前遍历,找价格最小数,在遇到下一个比他小的数之前,将原位置上的数变为当前最小数,从前往后用地雷币去购买。

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N]
int main()
{
	int n,mi=INT_MAX;
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	for(int i=n;i>=1;i--)
	{
		mi=min(mi,a[i]);//找到较小数
		a[i]=mi;//直接将原数,变为最小值
	}
	int t=0,ans=0;
	for(int i=1;i<=n;i++)
	{
        t++;//每次地雷币增加1
		if(a[i]<=t)//判断当前币够不够买此地雷
		{
            int s=t/a[i];
			ans+=s;
            t=t-s*a[i];//计算剩下来的地雷币
		}
	}
	cout<<ans;
	return 0;
}
F优秀字符串

这道题可以算一道签到题,我们需要判断

1.字符长度是否为5;

2.s[2]==s[4];

3.s[0]!=s[1]!=s[2]!=s[3];

#include <iostream>
#include <string>
using namespace std;

int main() {
	int t;
	cin >> t;
	int sum = 0;
	while (t--) {
		string s;
		int c = 1;
		cin >> s;
		if (s.size() == 5) {
			if (s[2] == s[4]) {
				for (int i = 0; i <= 2; i++) {
					for (int j = i + 1; j <= 3; j++) {
						if (s[i] == s[j]) {
							c = 0;
						}
					}
				}
				if (c == 1)
					sum++;
			}
		}
	}
	cout << sum << endl;
}

J 排列与合数

根据题目思考,在五位数中没有-1这种情况

当出现0 2 4 5 6 8时,可直接将其放到最后一位,但要注意前倒零的问题

#include <iostream>
using namespace std;
int check(char c) {
	if (c == '0' || c == '2' || c == '4' || c == '6' || c == '8' || c == '5')
		return 1;
	else
		return 0;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--) {
		string s;
		cin >> s;
		if (check(s[4]) == 1) 
        {
			cout << s << endl; 
			continue;
		} 
        else {
			for (int i = 0; i <= 3; i++) {
				if (check(s[i]) == 1) {
					swap(s[i], s[4]);
					break;
				}
			}
			cout << s << endl;

		}
	}
	return 0;
}
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值