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

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

题干

2024牛客寒假算法基础集训营3_第1张图片2024牛客寒假算法基础集训营3_第2张图片

题解:

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

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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"<>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

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

题干:

2024牛客寒假算法基础集训营3_第3张图片

题解:

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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;
    vectora(n);
    for(int i=0;i>a[i];
    int cnt=0,tmp=0;
    for(int i=0;i>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

B :智乃的数字手串

题干:

2024牛客寒假算法基础集训营3_第4张图片

题解:

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

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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;
    vectora(n);
    for(int i=0;i>a[i];
    if(n==1){
        cout<<"qcjj"<>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

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

题干:2024牛客寒假算法基础集训营3_第5张图片

题解:

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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;
    vectora(n);
    for(int i=0;i>a[i];
    int res=-1e9,tmp=0;
    vectorb;
    if(k==1){
        for(int i=0;i>T;
   for(int i=1;i<=T;i++){
      solve();
   }
    return 0;
}

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

题干:2024牛客寒假算法基础集训营3_第6张图片

题解:

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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"<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(!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)

题干:

2024牛客寒假算法基础集训营3_第7张图片

题解:

#include
using namespace std;
#define int long long 
const int N =1e6+10;
const int INF=0x3f3f3f3f;
typedef pair 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 > v;
int check(){
    for(auto [x,y,z]:v){
        if(z==1){
            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;
}

你可能感兴趣的:(算法)