Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)

Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2) Problem B+Problem D

B. William the Vigilant
作为一个号称世界上最懒的作者,我只把重要的圈了出来
You are given a string s of length n only consisting of characters “a”, “b” and “c”. There are q queries of format (pos,c), meaning replacing the element of string s at position pos with character c. After each query you must output the minimal number of characters in the string, which have to be replaced, so that the string doesn’t contain string “abc” as a substring. A valid replacement of a character is replacing it with “a”, “b” or “c”.
意思就是:会给你一个数i还有一个字母c将i位置上的字母更改成c染后在输出最小的大小意思就是把这一串子母中连续的abc都取出(歪果仁说话字数好多)(切记每次更换后保留)

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t,n,ans=0,i;
    string s;
    cin>>n>>t;
    cin>>s;//cin string
    for(i=0;i<n-2;i++){//delet the substrings abc from string
        if(s[i]=='a'&&s[i+1]=='b'&&s[i+2]=='c') ans++;
    }
    while(t--){
        int sum=0,num=0,k=ans,now;
        char c;
        cin>>now>>c;
        for(i=now-3;i<=now+1;i++){
            if(s[i]=='a'&&s[i+1]=='b'&&s[i+2]=='c') sum++;//find the amount of strings that can be deleted before the changing
        }
        s[now-1]=c;//change
        for(i=now-3;i<=now+1;i++){
            if(s[i]=='a'&&s[i+1]=='b'&&s[i+2]=='c') num++;//find the amount of strings that can be deleted 
        }
        cout<<k-sum+num<<endl;//k means the amount before
        ans=k-sum+num;//remember k
    }
    return 0;
}

D. Social Network
本想更新C,但是发现自己是一个蒟蒻所以来写一下D吧,(并查集还是挺好的)
意思就是:有一个经济团体,然后朋友越多越好(一看就是并查集🐕U•ェ•*U)然后给出t个询问,表示第x个人必须要与第y个人成为朋友
//切记一定要加一个sort否则就可能吧所有小的都加上了,但是忘记大的。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,t,f[1010],k[1010];
int get(int x){
    if(x==f[x]) return x;
    return f[x]=get(f[x]); 
}
bool cmp(int x,int y){
    return x>y;
}
int main(){
    cin>>n>>t;
	for(int i=1;i<=n;i++) {
		f[i]=i;
		k[i]=1;
	} 
    int cnt=0;
    while(t--){
        int x,y;
		cin>>x>>y;// numbers of people which must have a connection according to condition i.
        int fx=get(x);
        int fy=get(y);
        if(fx==fy) cnt++;//meaning that they are already connected
        else {
        	f[fy]=fx;//add an edge
			k[fx]+=k[fy];//friends add up as well
		}
		vector<int> v;
        //v[i] means that for person i he has v[i] friends
        for(int i=1;i<=n;i++){
            if(f[i]==i) v.push_back(k[i]);
        }
        sort(v.begin(),v.end(),cmp);
        int ans=0;//the total number of friends
        for(int i=0;i<=cnt&&i<v.size();i++) ans+=v[i];//it's sorted so that it will add together the biggest first
        cout<<ans-1<<endl;//minus yourself
    }
    return 0;
}

求点赞,有问题问我哦!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值