牛客模拟赛1【普及组】

题号题目
T1牛牛的密码
T2牛牛的跳跳棋
T3牛牛的最大兴趣组
T4牛牛的滑动窗口
得分120/120

T1

思路

直接照题意模拟即可。

代码

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
char xy[100010],dy[100010],sz[100010],ts[100010];
int c1,c2,c3,c4,w1,w2,w3,w4;
string s;
int main()
{
	getline(cin,s);
	for(int i=0; i<=s.size()-1; i++)
	 {
	 	if(s[i]>='a'&&s[i]<='z')
	 	  xy[++c1]=s[i],w1=1;
	 	else if(s[i]>='A'&&s[i]<='Z')
	 	  dy[++c2]=s[i],w2=1;
	 	else if(s[i]>='0'&&s[i]<='9')
	 	  sz[++c3]=s[i],w3=1;
        else
	 	  ts[++c4]=s[i],w4=1;
	 }
	if(w1+w2+w3+w4==4)
	  cout<<"password level:"<<4<<endl;
	else if(w1+w2+w3+w4==3)
	  cout<<"password level:"<<3<<endl;
	else if(w1+w2+w3+w4==2)
	  cout<<"password level:"<<2<<endl;
	else
	  cout<<"password level:"<<1<<endl;
	if(c1!=0)
	 {
	 	for(int i=1; i<=c1; i++)
	 	   cout<<xy[i];
	 	cout<<endl;
	 }
	else
	  cout<<"(Null)"<<endl;
	if(c2!=0)
	 {
	 	for(int i=1; i<=c2; i++)
	 	   cout<<dy[i];
	 	cout<<endl;
	 }
	else
	  cout<<"(Null)"<<endl;
	if(c3!=0)
	 {
	 	for(int i=1; i<=c3; i++)
	 	   cout<<sz[i];
	 	cout<<endl;
	 }
	else
	  cout<<"(Null)"<<endl;
	if(c4!=0)
	 {
	 	for(int i=1; i<=c4; i++)
	 	   cout<<ts[i];
	 	cout<<endl;
	 }
	else
	  cout<<"(Null)"<<endl;
	return 0;
}

T2

未做出

T3

未做出

T4

思路

看题发现可以直接用单调队列维护
每循环一次就维护最大最小值,
那么时间复杂度就是 O ( n 2 ) O(n^2) O(n2),可得50分。

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long q[4000010],a[4000010];
long long sum1[4000010],sum2[4000010];
long long n,x,h=1,t,c,ans;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
       scanf("%lld",&a[i]);
    for(int k=1; k<=n; k++)
     {
     	t=0,h=1,c=0;
     	for(int i=1; i<=n; i++)
     	 {
           while(h<=t&&q[h]<i-k+1)
             h++;
     	   while(h<=t&&a[i]<a[q[t]])
     	     t--;
           q[++t]=i;
           if(i>=k)
             sum1[++c]=a[q[h]];
         }
    	t=0,h=1,c=0;
    	for(int i=1; i<=n; i++)
     	 {
           while(h<=t&&q[h]<i-k+1)
             h++;
     	   while(h<=t&&a[i]>a[q[t]])
     	     t--;
           q[++t]=i;
           if(i>=k)
             sum2[++c]=a[q[h]];
         }
        for(int i=1; i<=c; i++)
           ans=ans+sum1[i]*sum2[i];
        printf("%lld ",ans);
        ans=0;
     }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值