牛客周赛部分题解

比赛地址:牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

A.小红的对错判断

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long  
#define ull unsigned long long

void solve() {
    string ssr;
    cin>>ssr;
    int a=ssr.length();
    if(a==3)
    {
        if(ssr[0]=='y'||ssr[0]=='Y')
        {
            if(ssr[1]=='e'||ssr[1]=='E')
            {
                if(ssr[2]=='s'||ssr[2]=='S')
                {
                    cout<<"accept"<<endl;
                    return;
                }
            }
        }
    }
    cout<<"wrong answer"<<endl;
} 

signed main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    ll t = 1; 
    // std::cin >> t;
    while (t--) {
        solve();
    }
}

B.小红的幂表达

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x;
    cin >> x;
    cout << x << endl;
    cout<<"="<<x<<"^1"<<endl;
    for(int i=sqrt(x);i>=2;i--)
    {
        int sum=0;
        int j=x;
        while(1)
        {
            if(j%i==0)
            {
                j/=i;
                sum++;
                if(j==1)
                {
                    cout<<"="<<i<<"^"<<sum<<endl;
                    break;
                }
            }
            else
            {
                break;
            }
        }
    }

    return 0;
}

C.小红的前缀询问

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    unordered_map<long long int, int> ssr;
    long long int pairCount = 0;
    vector<long long int> result(n);

    for (int i = 0; i < n; ++i) {
        ssr[a[i]]++;
        int newPairs = ssr[a[i]] - 1;
        pairCount += newPairs;
        result[i] = pairCount;
    }
    for (int i = 0; i < n-1; ++i) {
        cout << result[i] <<" ";
    }
    cout << result[n-1];
    return 0;
}

D.红和小紫的博弈游戏

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

void solve() {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int totalSum = a + b + c + d;
    if (totalSum == 0||totalSum==1) 
    {
        cout << "yukari" << endl;
        return;
    }
    int x=a+d;
    int y=b+c;
    x=min(x,y);
    if(x%2)
    {
        cout << "kou" << endl;
    }
    else
    {
        cout << "yukari" << endl;
    }
    
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
相关推荐
FlightYe4 小时前
视界原理之3D视频(四):裸眼、眼镜和头显
android·linux·c++·3d·ffmpeg·音视频
ZhengEnCi5 小时前
GPT-6 Astra 爆改 Qwen 权重真有那么神吗:权重空间编程 0.016% 参数的真相
算法·架构
罗西的思考5 小时前
【轻量化复刻大模型 / KIMI K3】KDA(Kimi Delta Attention):并行
人工智能·算法·机器学习
by209996 小时前
C++ 智能指针的所有权与使用
开发语言·c++·经验分享
Rover Ramble6 小时前
C++ 用互斥锁实现读写锁
开发语言·c++
你怎么知道我是队长6 小时前
C++零基础入门第2周:数据类型、运算符与表达式完全指南(附20段可运行代码+避坑清单)
c++
say_fall7 小时前
【Linux系统编程】Ext 文件系统:磁盘与存储、文件与目录、现代计算机究竟如何寻找文件
linux·运维·服务器·数据库·c++
雪落漂泊7 小时前
C++算法 滑动窗口篇(下)
开发语言·c++
夜不会漫长7 小时前
C++:红黑树
数据结构·算法
AI备案指南-满满8 小时前
算法备案审核不通过,一般是什么原因?
java·人工智能·算法·大模型备案·算法备案·大模型登记