牛客周赛 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;
}
相关推荐
悦悦子a啊4 分钟前
PTA:jmu-ds-最短路径
c++·算法·图论
小王努力学编程41 分钟前
高并发内存池(三):TLS无锁访问以及Central Cache结构设计
jvm·数据结构·c++·学习
草莓啵啵~1 小时前
数据结构--二叉树
数据结构
Watink Cpper1 小时前
[数据结构高阶]并查集初识、手撕、可以解决哪类问题?
数据结构·图论··并查集
什码情况3 小时前
星际篮球争霸赛/MVP争夺战 - 华为OD机试真题(A卷、Java题解)
java·数据结构·算法·华为od·面试·机试
字节高级特工3 小时前
【C++】”如虎添翼“:模板初阶
java·c语言·前端·javascript·c++·学习·算法
.Vcoistnt3 小时前
Codeforces Round 1024 (Div. 2)(A-D)
数据结构·c++·算法·贪心算法·动态规划·图论
越甲八千3 小时前
MFC listctrl修改背景颜色
c++·mfc
炯哈哈3 小时前
【上位机——MFC】序列化机制
开发语言·c++·mfc·上位机
程序员爱钓鱼3 小时前
循环语句:for、range -《Go语言实战指南》
java·数据结构·算法