1024 第二届成员积分赛 C3 1st 题解 By 小江

本贴最后更新于 969 天前,其中的信息可能已经事过境迁

比赛页面

X1. 小江的口袋

最少需要的口袋数就等于出现次数最多的价值

#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int a[1100]={0},ans=0,n;
    cin>>n;
    for(int i=0;i<n;i++) {
        int x;
        cin>>x;
        a[x]++;
        ans=max(ans,a[x]);
    }
    cout<<ans<<endl;
}

X2. 小丁爬楼梯

题意:给出一个长为 n 的数列,求上升子串的个数,以及每个上升子串的长度(保证每个上升子串都从 1 开始,并且每次递增 1)

思路:由于输入保证从一开始,那么,输入时,如果为一,那么开始计数,碰到下一个 1,重置,然后重新计数即可

#include <iostream>
using namespace std;
int ans[1005];
int main() {
    int n,x,t,cnt;
    cin>>n;
    t=0;
    for(int i=0;i<n;i++) {
        cin>>x;
        if(x==1) ans[t++]=cnt,cnt=0;
        cnt++;
    }
    ans[t]=cnt;
    cout<<t<<endl;
    for(int i=1;i<=t;i++)
	    cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

X3. 乔老师喜欢的数字

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n;
    while(cin>>n) {
        if(n%3==0)
		cout<<1<<' '<<1<<' '<<n-2<<endl;
        else if(n%3==1)
		cout<<2<<' '<<1<<' '<<n-3<<endl;
        else
		cout<<2<<' '<<2<<' '<<n-4<<endl;
    }
    return 0;
}

X4. 小花的评论

思路:x-y 的绝对值大于 z 就有稳定的答案,同时特判 z 等于 0.

#include <bits/stdc++.h>
using namespace std;
int main() {
    int x, y, z;
    cin >> x >> y >> z;
    if (z < abs(x - y) || z == 0) {
        if (x > y)
            cout << "+" << endl;
        else if (y > x)
            cout << "-" << endl;
        else
            cout << "0" << endl;
    }
    else
        cout << "?" << endl;
    return 0;
}

X5. 打字比赛

#include <bits/stdc++.h>
using namespace std;
int main () {
	int s,v1,v2,t1,t2;
	scanf("%d%d%d%d%d",&s,&v1,&v2,&t1,&t2);
	int s1=t1*2+s*v1,s2=t2*2+s*v2;
	if (s1<s2)
		printf("First\n");
	if (s1>s2)
		printf("Second\n");
	if (s1==s2)
		printf("Friendship\n");
	return 0;
}

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...