2024牛客寒假算法基础集训营3

A 智乃与瞩目狸猫、幸运水母、月宫龙虾

题干

题解:

就看两个字符串的第一个字母是否相同

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[] = {1,0,0,-1};
int ddy[] = {0,1,-1,0};
void solve(){
  string s1,s2;
  cin>>s1>>s2;
  if(s1[0]==s2[0] or s1[0]-32==s2[0] or s1[0]+32==s2[0]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

L:智乃的36倍数(easy version)

题干:

题解:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[] = {1,0,0,-1};
int ddy[] = {0,1,-1,0};
void solve(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int cnt=0,tmp=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j){
                tmp=a[i]*10;
                if(a[j]==10)tmp*=10;
                   tmp+=a[j];
                if(tmp%36==0) cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    // cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

B :智乃的数字手串

题干:

题解:

诈骗题,n为奇数就位清楚姐姐,反之为智乃。

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[] = {1,0,0,-1};
int ddy[] = {0,1,-1,0};
void solve(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    if(n==1){
        cout<<"qcjj"<<endl;
        return ;
    }
     if(n==2){
        cout<<"zn"<<endl;
        return ;
    }
    if(n&1) cout<<"qcjj"<<endl;
    else cout<<"zn"<<endl;
    }
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

D:chino's bubble sort and maximum subarray sum(easy version)

题干:

题解:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[] = {1,0,0,-1};
int ddy[] = {0,1,-1,0};
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int res=-1e9,tmp=0;
    vector<int>b;
    if(k==1){
        for(int i=0;i<n-1;i++){
            b=a;
            int kk=-1e9;
            int tmp1=b[i];b[i]=b[i+1];b[i+1]=tmp1;
            tmp=b[0];
            for(int j=1;j<n;j++){
                tmp=max(b[j],b[j]+tmp);
                kk=max(kk,tmp);
            }
            res=max(res,kk);
            }
        }
        else{
            tmp=a[0];
            for(int i=1;i<n;i++){
                tmp=max(a[i],a[i]+tmp);
                res=max(res,tmp);
            }
        }
        cout<<res<<endl;
    }
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    // cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

G:智乃的比较函数(easy version)

题干:

题解:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[] = {1,0,0,-1};
int ddy[] = {0,1,-1,0};
void solve(){

        int n;
        cin>>n;
        if(n==1){
        int x,y,z;
        cin>>x>>y>>z;
        if(x==y and z==1) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
        return ;
    }
        else{    
            vector<int>a(4,-1),b(4);
        bool f=1;
        for(int i=1;i<=2;i++){
            int x,y,z;
            cin>>x>>y>>b[i];
            if(x==y and b[i]==1) f=0;
            if(a[x]!=-1 and  a[y]!=-1){
                if(b[i]==0){
                    if(b[i-1]==0) a[x]=a[y];
                    if(a[x]<a[y])f=0;
                }else{
                    if(a[x]>=a[y])f=0;
                }
            }else{
                if(!b[i])a[x]=2,a[y]=1;
                else a[x]=1,a[y]=2;
            }
        }
        if(f)cout<<"Yes\n";
        else cout<<"No\n";
        }
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

H 智乃的比较函数(normal version)

题干:

题解:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair<int, int> pII;
#define x first
#define y second
typedef long long ll;
#define pb push_back
#define P push
const int mod=1e9+7;
#define endl '\n'
const double eps=1e-5;
int ddx[]={1,1,0,-1};
int ddy[]={0,1,1,1};
int dp[1001];
vector<tuple<int,int,int> > v;
int check(){
    for(auto [x,y,z]:v){
        if(z==1){
            if(dp[x]<dp[y])continue;
            else return 0;
        }
        else{
            if(dp[x]>=dp[y])continue;
            else return 0;
        }
    }
    return 1;
}
void solve(){
    v={};
    int n;
          cin>>n;
          int a,b,c;
        while(n--){
            cin>>a>>b>>c;
            v.push_back({a,b,c});
        }
        int ans=0;
        for(int i=1;i<=3;i++)
            for(int j=1;j<=3;j++)
                for(int k=1;k<=3;k++){
                    dp[1]=i; dp[2]=j; dp[3]=k;
                   ans|=check();
        }
        if(ans)cout<<"Yes\n";
        else cout<<"No\n";
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T= 1;
    cin>>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值