牛客周赛部分题解

比赛地址:牛客竞赛_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;
}
相关推荐
许愿与你永世安宁30 分钟前
力扣343 整数拆分
数据结构·算法·leetcode
爱coding的橙子33 分钟前
每日算法刷题Day42 7.5:leetcode前缀和3道题,用时2h
算法·leetcode·职场和发展
ruanjiananquan9935 分钟前
c,c++语言的栈内存、堆内存及任意读写内存
java·c语言·c++
满分观察网友z1 小时前
从一次手滑,我洞悉了用户输入的所有可能性(3330. 找到初始输入字符串 I)
算法
持梦远方1 小时前
C 语言基础入门:基本数据类型与运算符详解
c语言·开发语言·c++
YuTaoShao1 小时前
【LeetCode 热题 100】73. 矩阵置零——(解法二)空间复杂度 O(1)
java·算法·leetcode·矩阵
Heartoxx1 小时前
c语言-指针(数组)练习2
c语言·数据结构·算法
大熊背2 小时前
图像处理专业书籍以及网络资源总结
人工智能·算法·microsoft
满分观察网友z2 小时前
别怕树!一层一层剥开它的心:用BFS/DFS优雅计算层平均值(637. 二叉树的层平均值)
算法
江理不变情2 小时前
图像质量对比感悟
c++·人工智能