牛客周赛 Round 42

小红叕战小紫

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
void solve(){
    string s;
    cin>>s;
    if(s.length()<=1)cout<<"yukari";
    else cout<<"kou"<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while(t--)solve();
    return 0;
}

小红的数组移动

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
void solve(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    string s;
    cin>>s;
    int j=1,ans=0;
    for(auto i:s){
        if(i=='R'&&j<n)ans=(ans+a[++j])%mod;
        else if(i=='L'&&j>1)ans=(ans+a[--j])%mod;
        else ans=(ans+a[j])%mod;
    }
    cout<<ans%mod<<endl;
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while(t--)solve();
    return 0;
}

小红的素数合并

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+10;
set<int>st;
void solve(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int i=1;
    if(n&1){
        st.insert(a[n]);
        n--;
    }
    for(i=1;i<=n/2;i++)st.insert(a[i]*a[n-i+1]);
    if(st.size()!=1)cout<<abs(*prev(st.end())-*st.begin())<<endl;
    else cout<<0<<endl;
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while(t--)solve();
    return 0;
}

小红的树上删边

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>E;
vector<bool>vis;
int ans=0,f=1;
int dfs(int u,int fa){
    vis[u]=1;
    int len=1;
    for(auto v:E[u]){
        if(!vis[v]){
            int lenc=dfs(v,u);
            len+=lenc;
        }
    }
    if(len%2==0&&u!=1)ans++;
    return len;
}
void solve(){
    int n;
    cin>>n;
    E.resize(n+1);
    vis.resize(n+1,false);
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    if(n&1){cout<<-1<<endl;return ;}
    dfs(1,0);
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while(t--)solve();
    return 0;
}
相关推荐
h39742 小时前
DirectShow过滤器开发-视频源过滤器
c++·windows·音视频·directshow
程序猿编码3 小时前
榨干 RTX5090 算力!Qwen3 专用单卡推理引擎,手写C++/CUDA 算子实现 MTP 推测解码
开发语言·c++·大模型推理·qwen3·多模态推理
西飘客4 小时前
vs 怎么根据dll 生成lib文件
c++·qt
程序员老陆5 小时前
深入理解 C++ thread_local:线程私有存储的正确打开方式
开发语言·c++·程序设计
码完就睡7 小时前
数据结构——红黑树
数据结构
码爸7 小时前
数据结构详细介绍
数据结构
半杯咖啡半行码8 小时前
C++ 编程与 STL 模板:从泛型编程到内存安全详解
开发语言·c++
xh didida9 小时前
Linux -- 基础IO
linux·服务器·开发语言·c++
垆边人似月.9 小时前
华为机试题 :两数之和
c++·算法·华为
个 人 练 习 生9 小时前
C++ string 类模拟实现:从底层理解字符串(上)
开发语言·c++·经验分享·学习·程序人生