首先这次比赛在赛场中我们完全可以将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;
}