round 634

 

AB水题

 

C

只需考虑不重复串是否包括上重复串的那个字母这两种情况

#include <bits/stdc++.h>
#define debug freopen("r.txt","r",stdin)
#define mp make_pair
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const int INF = 0x3f3f3f3f; 
const int mod = 998244353;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;}
ll qpow(ll p,ll q){return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;}
int t,n,a[maxn],k,j,i,maxx,num;
map <int,int> mapp;
int main()
{
//    debug;
    t=read();
    while (t--)
    {
        n=read();
        maxx=-INF;
        for (i=1;i<=n;i++) 
        {
            a[i]=read();
            mapp[a[i]]++;
            maxx=max(maxx,mapp[a[i]]);
        }
        sort(a+1,a+1+n);
        num=unique(a+1,a+1+n)-a-1;
        k=min(num,maxx-1);
        j=min(num-1,maxx);
        cout<<max(k,j)<<endl;
        for (i=1;i<=n;i++) mapp[a[i]]=0;
    }
    return 0;
}
View Code

 

D

前方if语句警告,选的9个点要刚好覆盖完每一行每一列每个方阵

#include <bits/stdc++.h>
#define debug freopen("r.txt","r",stdin)
#define mp make_pair
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const int INF = 0x3f3f3f3f; 
const int mod = 998244353;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;}
ll qpow(ll p,ll q){return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;}
int t,i,j;
char c[10][10];
int main()
{
//    debug;
    t=read();
    while (t--)
    {
        for (i=1;i<=9;i++)
            for (j=1;j<=9;j++)
                cin>>c[i][j];
        if (c[1][1]!='9') c[1][1]='9';
            else c[1][1]='1';
        if (c[2][4]!='9') c[2][4]='9';
            else c[2][4]='1';
        if (c[3][7]!='9') c[3][7]='9';
            else c[3][7]='1';
        if (c[4][2]!='9') c[4][2]='9';
            else c[4][2]='1';
        if (c[5][5]!='9') c[5][5]='9';
            else c[5][5]='1';
        if (c[6][8]!='9') c[6][8]='9';
            else c[6][8]='1';
        if (c[7][3]!='9') c[7][3]='9';
            else c[7][3]='1';
        if (c[8][6]!='9') c[8][6]='9';
            else c[8][6]='1';
        if (c[9][9]!='9') c[9][9]='9';
            else c[9][9]='1';
        for (i=1;i<=9;i++)
        {
            for (j=1;j<=9;j++)
                cout<<c[i][j];
            cout<<endl;
        }
    }
    return 0;
}
View Code

 

E

可以看到a这个数组最大才200,我们可以尝试枚举这两百个数,来让它做为头尾x这两个串。

我们可以把某个数a[i]所在的每个位置扔进一个vector里面,这时候只需枚举x的长度,看a[i]的前后位置去到哪,然后在这中间位置里面找出最长的y串出来,这里就需要预处理出这两百个数的前缀和出来,以方便找出答案了。

#include <bits/stdc++.h>
#define debug freopen("r.txt","r",stdin)
#define mp make_pair
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const int INF = 0x3f3f3f3f; 
const int mod = 998244353;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;}
ll qpow(ll p,ll q){return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;}
int n,maxx,ans,i,j,b[maxn][210],t,a[maxn],l,r;
int main()
{
//    debug;
    t=read();
    while (t--)
    {
        n=read();
        for (i=1;i<=n;i++) 
        {
            a[i]=read();
        }
        vector <vector<int>> G(210);
        for(j=1;j<=200;j++) 
        {
            for(i=1;i<=n;i++) 
            {
                b[i][j]=b[i-1][j]+(a[i]==j);
                if(a[i]==j) G[j].push_back(i);
            }
        }
        ans=-INF;
        for (i=1;i<=200;i++)
            for (l=0;l<int(G[i].size());l++)
            {
                r=int(G[i].size())-1-l;
                if (l>r) break;
                if (l==r) ans=max(ans,int(G[i].size()));
                else
                {
                    maxx=-INF;
                    for (j=1;j<=200;j++)
                        maxx=max(maxx,b[G[i][r]-1][j]-b[G[i][l]][j]);
                    ans=max(ans,2*(l+1)+maxx);
                }
            }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

 

posted @ 2020-04-15 23:30  Y-KnightQin  阅读(92)  评论(0编辑  收藏  举报