牛客周赛 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;
}
相关推荐
哈里谢顿4 小时前
跳表(Skip List):简单高效的有序数据结构
数据结构
xlp666hub9 小时前
Leetcode 第三题:用C++解决最长连续序列
c++·leetcode
会员源码网10 小时前
构造函数抛出异常:C++对象部分初始化的陷阱与应对策略
c++
xlp666hub12 小时前
Leetcode第二题:用 C++ 解决字母异位词分组
c++·leetcode
不想写代码的星星13 小时前
static 关键字:从 C 到 C++,一篇文章彻底搞懂它的“七十二变”
c++
xlp666hub1 天前
Leetcode第一题:用C++解决两数之和问题
c++·leetcode
任沫1 天前
字符串
数据结构·后端
不想写代码的星星2 天前
C++继承、组合、聚合:选错了是屎山,选对了是神器
c++
祈安_2 天前
Java实现循环队列、栈实现队列、队列实现栈
java·数据结构·算法
不想写代码的星星3 天前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++