牛客周赛部分题解

比赛地址:牛客竞赛_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;
}
相关推荐
大江东去浪淘尽千古风流人物12 分钟前
【VLN】VLN(Vision-and-Language Navigation视觉语言导航)算法本质,范式难点及解决方向(1)
人工智能·python·算法
rainbow688936 分钟前
Linux文件描述符与重定向原理
c++
努力学算法的蒟蒻1 小时前
day79(2.7)——leetcode面试经典150
算法·leetcode·职场和发展
2401_841495641 小时前
【LeetCode刷题】二叉树的层序遍历
数据结构·python·算法·leetcode·二叉树··队列
AC赳赳老秦1 小时前
2026国产算力新周期:DeepSeek实战适配英伟达H200,引领大模型训练效率跃升
大数据·前端·人工智能·算法·tidb·memcache·deepseek
CodeSheep程序羊1 小时前
拼多多春节加班工资曝光,没几个敢给这个数的。
java·c语言·开发语言·c++·python·程序人生·职场和发展
2401_841495641 小时前
【LeetCode刷题】二叉树的直径
数据结构·python·算法·leetcode·二叉树··递归
budingxiaomoli1 小时前
优选算法-字符串
算法
编程小白20262 小时前
从 C++ 基础到效率翻倍:Qt 开发环境搭建与Windows 神级快捷键指南
开发语言·c++·windows·qt·学习
qq7422349842 小时前
APS系统与OR-Tools完全指南:智能排产与优化算法实战解析
人工智能·算法·工业·aps·排程