欢乐赛#38题解
2025-01-13 10:58:10
发布于:四川
这次欢乐赛恰逢期末考试,也是抢着时间做完了,然后现在来卷个题解
T1   转义字符输出
输入输出样例:
输入#1 无
输出#1 
分析:
这是一道考察基础知识的题,最简单的方法就是用ASCII表
代码:
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
int main()
{
	cout<<char(92);
	return 0;
}
T2 28转化
输入输出样例:
输入#1 12345678
输出#1 18345672
分析:
仅需遍历一遍字符串然后用if就行了
注意要用if();else if();某鱼当时写了个错误示范if(xxx);if(xxx);然后直接wa完
代码:
#include <iostream>
#include <stdio.h>
#include <cstring>
#define LL long long
using namespace std;
int main()
{
	string str;
    cin>>str;
    for(int i=0;i<str.size();i++){
        if(str[i]=='2') str[i]='8';
        
        else if(str[i]=='8') str[i]='2';
    }
    cout<<str;
	return 0;
}
T3 商品降价
输入输出样例:
输入#1
5
10 2 8 4 6
输出#1
25
分析:
最贵的那件商品的价格减半,所以我们只需要先排序然后把最大的减半,然后再相加就行
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;
vector<LL> V;
bool cmp(LL a,LL b){
    return a>b;
}
int main()
{
    int T;
	for(cin>>T;T;T--){
        int t;
        cin>>t;
        V.push_back(t);
    }
    sort(V.begin(),V.end(),cmp);
    V[0]/=2;
    int h=0;
    for(auto i:V){
        h+=i;
    }
    cout<<h;
	return 0;
}
面对新人:这里我们使用了vector来代替数组,用了algorithm中的sort函数来排序
关于vector
关于sort
T4 英文字母
分析:首先多此询问,所以建议封装函数。
简单if判断直接拿下
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
void solve(){
    LL a,b;
    cin>>a>>b;
    if(a>6||(a==6&&b<=1116)){
        cout<<"Gold\n";
    }
    else if(a>4||(a==4&&b<=556)){
        cout<<"Silver\n";
    }
    else if(a>3||(a==3&&b<=357)){
        cout<<"Bronze\n";
    }
    else if(a>=1){
        cout<<"Ferrum\n";
    }
    else{
        cout<<"Traval\n";
    }
}
int main()
{
	int T;
    for(cin>>T;T;T--) solve();
	return 0;
}
T5 染色问题
分析:首先多此询问,所以建议封装函数。
然后不难看出这是一个递推,dp[i]=dp[i-1]*(m-1)(dp[0]=m)
哦,注意要取余,由于数据较小,所以可以不用快速幂
代码
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
const LL N=998244353;
int main()
{
	int T;
    for(cin>>T;T;T--){
        LL t,k;
        cin>>t>>k;
        LL n=k;t--;
        for(LL i=0;i<t;i++) n=(n*(k-1))%N;
        cout<<n<<'\n';
    }
	return 0;
}
T6 放烟花啦
分析:简单分析可得
代码:
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
int main()
{
    int T;
    for(cin>>T;T;T--){
    	LL ans=0,a,b,m;
    	cin>>a>>b>>m;
   	 	m++;
		if(m%a==0)
			ans+=m/a;
		else ans+=m/a+1;
		if(m%b==0)
			ans+=m/b;
		else ans+=m/b+1;
		cout<<ans<<'\n';
    }
	return 0;
}
最后祝大家期末加油
全部评论 1
我和“我的世界MC不死!”的小伙伴都在ACGO等你,快用这个专属链接加入我们吧!https://www.acgo.cn/application/1879044929487945728
2025-01-15 来自 湖北
1









有帮助,赞一个