首页 > 其他分享 >Codeforces Round #824 (Div. 2)

Codeforces Round #824 (Div. 2)

时间:2022-10-04 17:02:17浏览次数:69  
标签:arr int Codeforces l2 solve l1 824 Div include

Codeforces Round #824 (Div. 2)

A

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define endl '\n'
using namespace std;
int t,n;
inline void solve(){
    cin>>n;
    cout<<(n-6)/3<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
    while(t--)solve();
	return 0;
}

假设l1,l2,l3中,大小顺序为l1<=l2<=l3;
min={l2-l1,l3-l1,l3-l2};
很明显最大时l1=1(很容易证明),
因此l3+l2=n-4;
min={l2-1,n-4-2l2};
即当l2-1=n-4-2
l2时取的最大
最大为l2-1=(n-3)/3-1=(n-6)/3
(目前做过的最难a题)

B

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define endl '\n'
using namespace std;
const int N=110;
int t;
int n;
int arr[N];
inline void solve(){
    cin>>n;
    cin>>arr[1];
    int ms=arr[1]*2-1;
    int ans=0;
    for(int i=2;i<=n;i++){
        cin>>arr[i];
        ans+=(arr[i]+ms-1)/ms-1;
    }
    cout<<ans<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
    while(t--)solve();
	return 0;
}

纯贪心题没什么好说的,既然每个数都必须严格小于a12,
那么大于他的数每次切a1
2-1就一定是最小切割次数(受a题影响,一直以为这是道数学证明题,想了半天,感觉应该和a交换下出题顺序的)。

C

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define endl '\n'
using namespace std;
const int N=1e5+10;
int t,n;
bool st[26];
int pre[26];
char str[N];
char mut[N];
inline void solve(){
    memset(pre,0,sizeof pre);
    memset(st,0,sizeof st);
    cin>>n;
    cin>>str;
    for(int i=0;i<n;i++){
        if(pre[str[i]-'a']){
            mut[i]=pre[str[i]-'a'];
            continue;
        }
        for(int j=0;j<26;j++){
            if(j==str[i]-'a')continue;
            if(!st[j]){
                bool flag=false;
                int k=j;
                int cnt=0;
                while(pre[k]){
                    cnt++;
                    if(pre[k]==str[i]){
                        flag=true;
                        break;
                    }
                    k=pre[k]-'a';
                }
                if(flag&&cnt!=25)continue;
                st[j]=true;
                pre[str[i]-'a']='a'+j;    
                mut[i]='a'+j;
                break;
            }
        }
    }
    for(int i=0;i<n;i++)cout<<mut[i];
    cout<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    cin>>t;
	while(t--)solve();
	return 0;
}

c题题干长的一批,读懂就好做,主要a->b->c->a这种问题就行了,
一定把前缀看完,如果他前缀出现过这个数,且他们的距离不是25那么跳过就行了。

标签:arr,int,Codeforces,l2,solve,l1,824,Div,include
From: https://www.cnblogs.com/xiuuix/p/16754040.html

相关文章