AtCoder ABC352 A-D题解

比赛链接:ABC352

Problem A:

签到题。

#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,X,Y,Z;
	cin>>N>>X>>Y>>Z;
	if((X<=Z && Z<=Y) || (Y<=Z && Z<=X))
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Problem B:

没什么好说的。看代码吧。

#include <bits/stdc++.h>
using namespace std;
int main(){
	string S,T;
	cin>>S>>T;
	int j=0;
	for(int i=0;i<T.size();i++){
		if(j<S.size() && T[i]==S[j]){
			cout<<i+1<<endl;
			j++;
		}
	}
	return 0;
}

Problem C:

出奇的简单,比以往的C简单很多。

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    long long h=0;
    int mx=0;
    for(int i=1;i<=N;i++){
        int A,B;
        cin>>A>>B;
        h+=A;
        mx=max(mx,B-A);
    }
    h+=mx;
    return 0;
}

Problem D:

这题用set不好吗?用什么乱七八糟的。

P记录位置。令当前数是x,则set里放的就是P_{x-K+1}P_x,ans每次对set里最大最小值的差取min即可。

#include <bits/stdc++.h>
using namespace std;
int p[200005];
int main(){
    int N,K;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        int P;
        cin>>P;
        P--;
        p[P]=i;
    }
    int ans=N;
    set<int> st;
    for(int i=0;i<N;i++){
        st.insert(p[i]);
        if(i>=K)
            st.erase(p[i-K]);
        if(i>=K-1)
            ans=min(ans,*st.rbegin()-*st.begin());
    }
    cout<<ans<<endl
    return 0;
}

以上就是本期的全部内容了,我们下期再见!

友情提醒:本期的代码都有问题,请不要无脑Ctrl C+Ctrl V。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值