ACGO欢乐赛#32题解(T1~T5)
2024-10-21 09:41:58
发布于:广东
此处没有前言
————————————————————————————————————————————
T1
这道题我们要注意的是:如果他刷题的数量不是3的倍数,那就说明他有一天刷了1或2道题。所以当他刷题的数量不是3的倍数的时候,我们除以3之后记得+1(int是自动取整的)。
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    if(n%3==0) cout << n/3;
    else cout << n/3+1;
	return 0;
}
T2
这道题就取小t1+t2,t3,t2+t3,t1,t1+t3,t2就行了。
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b+c,a) << endl;
    cout << min(a+c,b) << endl;
    cout << min(a+b,c);
	return 0;
}
T3
这道题要把一个指定位置改成负数,所以我们只要把不是那个位置的数加起来再减去那个位置的数。
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,a[1000000];
    cin >> n >> k;
    long long sum = 0;//我怕超范围,所以开了long long
    for(int i=1;i<=n;i++){
    	cin >> a[i];
        if(i!=k) sum += a[i];
    }
    cout << sum - a[k];
	return 0;
}
T4
这道题不是很难,但很坑,他要你输出的是“YE5“和”N0”。
再来讲讲思路:是12的倍数的我就不说了,而这个含有“12”的我要说一下。
我们首先可以获取他的每一位(个人建议从个位开始存),然后判断a[i] == 2 && a[i+1] == 1即可。
#include<bits/stdc++.h>
using namespace std;
bool check(long long n){
	int a[20],j = 0;
    long long pp = n;
    while(pp!=0){
    	a[j] = pp%10;
        pp/=10;
        j++;
    }
    for(int i=0;i<j-1;i++){
    	if(a[i]==2 && a[i+1]==1) return true;
    }
    return false;
}
int main(){
    long long n;
    cin >> n;
    if(n%12==0) cout << "YE5";
    else if(check(n)) cout << "YE5";
    else cout << "N0";
	return 0;
}
T5
这道题没啥好说的,根据题意去模拟就行了,唯一要会的就是swap函数。
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int x,y;
    cin >> x >> y;
    if(s[x-1]==s[y-1]){
    	s[x-1] = '#';
        s[y-1] = '#';
    }else swap(s[x-1],s[y-1]);
    cout << s;
	return 0;
}
讲完了,有更优解或错误欢迎指出
这里空空如也







有帮助,赞一个