国庆模拟赛04(下)

· · 个人记录

1、U559540 美味度

这道题正解使用快慢指针,但我用的方法……不知道是什么。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
map<int,int>a;
map<int,int>b;
map<int,int>c;
#define int long long
signed main(){
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        for(int i=1;i<=n;i++){
            cin>>b[i];
        }
        for(int i=1;i<=n;i++){
            c[i]=a[i]+b[i];
        }
        int ans=0;
        int cnt=0;
        int sum=0;
        for(int i=1;i<=n;i++){
            if(c[i]!=c[i-1]){
                ans=max(sum*cnt,ans);
                sum=a[i];
                cnt=1;
            }
            else{
                sum+=a[i];
                cnt++;
            }
        }
        ans=max(sum*cnt,ans);
        cout<<ans<<'\n';
    }
    return 0;
}

不知道为什么会用map估计是之前二维的搜索H \times W==2e5的搜索做多了。用map的时间复杂度要多,在落落的去电脑上测试是65分,洛谷是85,改用普通数组直接在洛谷上AC了。

2、跳棋

这题主要是把两个部分分拿到了,那个X和Y的数量都为1的情况很好判断(r-l)\bmod2判断就行了,但是X只有1个Y的数量不定的情况想了半天没想出来,于是和预判出题人直接

cout<<"X\n";

但是竟然他对了?! 20分:

#include<bits/stdc++.h>0
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        string s;
        cin>>s;
        int X=0,Y=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='X')X++;
            if(s[i]=='Y')Y++;
        } 
        if(X==1&&Y==1){
            int l=0,r=0;
            for(int i=0;i<s.size();i++){
                if(s[i]=='X')l=i;
                if(s[i]=='Y')r=i;
            }
            if((r-l)%2==0){
                cout<<"Y\n";
            }
            else{
                cout<<"X\n";
            }
        }
        else if(X==1){
            cout<<"X\n";
        }
    }
    return 0;
}

3、划船计划

这道题在比赛的时候把双指针写出来了,但是是按照纪念品分组思路来的,这个时候发现欸?w取什么?直接就等于最大值和最小值的平均值了,没有想到还要枚举w

50分:

#include<bits/stdc++.h>0
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        string s;
        cin>>s;
        int X=0,Y=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='X')X++;
            if(s[i]=='Y')Y++;
        } 
        if(X==1&&Y==1){
            int l=0,r=0;
            for(int i=0;i<s.size();i++){
                if(s[i]=='X')l=i;
                if(s[i]=='Y')r=i;
            }
            if((r-l)%2==0){
                cout<<"Y\n";
            }
            else{
                cout<<"X\n";
            }
        }
        else if(X==1){
            cout<<"X\n";
        }
    }
    return 0;
}