牛客周赛 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;
}
相关推荐
chao_78935 分钟前
链表题解——两两交换链表中的节点【LeetCode】
数据结构·python·leetcode·链表
南岩亦凛汀1 小时前
在Linux下使用wxWidgets进行跨平台GUI开发
c++·跨平台·gui·开源框架·工程实战教程
曦月逸霜1 小时前
第34次CCF-CSP认证真题解析(目标300分做法)
数据结构·c++·算法
galaxy_strive1 小时前
绘制饼图详细过程
开发语言·c++·qt
Unpredictable2223 小时前
【VINS-Mono算法深度解析:边缘化策略、初始化与关键技术】
c++·笔记·算法·ubuntu·计算机视觉
PingdiGuo_guo3 小时前
C++智能指针的知识!
开发语言·c++
Chuncheng's blog4 小时前
CentOS 7如何编译安装升级gcc至7.5版本?
linux·运维·c++·centos
吴声子夜歌4 小时前
OpenCV——Mat类及常用数据结构
数据结构·opencv·webpack
笑口常开xpr5 小时前
数 据 结 构 进 阶:哨 兵 位 的 头 结 点 如 何 简 化 链 表 操 作
数据结构·链表·哨兵位的头节点
愚润求学6 小时前
【C++】类型转换
开发语言·c++