第三次CCF计算机软件能力认证

第一题:

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int a[N];

int main(){
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x;scanf("%d",&x);
        a[x]++;
        if(i==0) cout<<a[x];
        else cout<<" "<<a[x];
    }
    return 0;
}

第二题:

#include<bits/stdc++.h>
using namespace std;
const int N=550;
int a[N][N];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) 
            scanf("%d",&a[i][j]);
    int x=1,y=1;
    bool flag=false;
    while(x!=n||y!=n){
        if(x<=n&&y<=n)
            cout<<a[x][y]<<" ";

        if(flag) x++,y--;
        else x--,y++;

        if(x==0){
            flag=true;
            x=1;
        }
        if(y==0){
            flag=false;
            y=1;
        }
    }
    cout<<a[x][y]<<endl;
    return 0;
}

第三题:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
struct P{
    int type;
    double p;
    int s;
    bool is_del;
    bool operator<(const P &t) const{
        return p<t.p;
    }
}a[N],b[N],tot[N];
int cnt;
int t1,t2;
ll as[N],bs[N];
int main(){
    //freopen("1.txt","r",stdin);
    string ss;
    while(cin>>ss){
        double p;int s;
        if(ss=="buy"){
            scanf("%lf%d",&p,&s);
            tot[++cnt]={1,p,s};
        }
        else if(ss=="sell"){
            scanf("%lf%d",&p,&s);
            tot[++cnt]={2,p,s};
        }
        else{
            int x;scanf("%d",&x);
            tot[x].is_del=true;
            tot[++cnt].is_del=true;
        }
    }
    set<double> se;
    for(int i=1;i<=cnt;i++){
        if(tot[i].is_del) continue;
        if(tot[i].type==1) a[++t1]=tot[i];
        else b[++t2]=tot[i];
        se.insert(tot[i].p);
    }
    sort(a+1,a+t1+1);
    sort(b+1,b+t2+1);
    for(int i=1;i<=t1;i++) as[i]=as[i-1]+(ll)a[i].s;
    for(int i=1;i<=t2;i++) bs[i]=bs[i-1]+(ll)b[i].s;
    set<double>::iterator it;
    int p1=0,p2=0;
    ll ress=0;
    double resp=0;
    for(it=se.begin();it!=se.end();it++){
        double ans=*it;
        while(p1+1<=t1&&a[p1+1].p<ans) p1++;
        while(p2+1<=t2&&b[p2+1].p<=ans) p2++;
        ll cnts=min(bs[p2],as[t1]-as[p1]);
        if(cnts>=ress)
            ress=cnts,resp=ans;
    }
    printf("%.2lf %lld\n",resp,ress);
    return 0;
}

第四题:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct edge{
    int x,y,w;
    edge(int x=0,int y=0,int w=0):x(x),y(y),w(w){}
    bool operator<(const edge &t)const {
        return w<t.w;
    }
}e[N];
int n,m;
int fa[N];
int getfather(int x){
    if(x==fa[x]) return x;
    else return fa[x]=getfather(fa[x]);
}

int kruscal(){
    int ans=0;
    sort(e+1,e+1+m);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++){
        int fa1=getfather(e[i].x);
        int fa2=getfather(e[i].y);
        if(fa1!=fa2){
            fa[fa1]=fa2;
            ans+=e[i].w;
        }
    }
    return ans;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
    printf("%d\n",kruscal());
    return 0;
}

第五题:

待补充

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值