牛客周赛 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;
}
相关推荐
Chester_19996 小时前
CSP202203C.计算资源调度器
开发语言·数据结构·c++·蓝桥杯
会周易的程序员7 小时前
给 PLC 写一个字节码虚拟机:STVM 虚拟机架构设计
开发语言·c++·虚拟机·软plc·iec61131·stvm
小灰灰搞电子7 小时前
完全驾驭 Qt 与数据库:C++ ORM 框架 QxOrm 原理与实践指南
数据库·c++·qt
QT界面美化性能优化8 小时前
QT+AI:使用AI技术为QT应用程序赋能
c++·人工智能·qt·opencv·qt教程·qt6.3
学习星球10 小时前
单调栈——从“找下一个更大的“到柱状图中的最大矩形
数据库·c++·算法·leetcode·xcode
小灰灰搞电子10 小时前
C++ 引用折叠详解
c++
专注仿真11 小时前
Spring AI 实现智能对话系统项目指南
数据结构·spring·机器学习
布莱克60511 小时前
数组详解:定义、作用、应用场景及与链表的区别(C/C++ 代码讲解)
c语言·开发语言·c++·数组
间歇性努力持续性发呆的野生快乐选手11 小时前
高级数据结构:树状数组
数据结构
牛油果子哥q12 小时前
C++内存池与对象池精讲:内存碎片、自定义分配器、对象池实现、STL allocator原理、工程落地与性能对比
java·开发语言·c++