黑龙江职业学院校赛第二场(同步赛)补题

A.龙职院卷怪争霸

alt

数据范围很小,直接暴力for循环就好,简单的签到题,也可以用单调栈来做

我的代码:

#include<bits/stdc++.h>
using namespace std;

const int N = 110;

int a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0;i < n;i ++) cin >> a[i];
    
    for (int i = 0;i < n;i ++)
    {
        int sum = 0;
        for (int j = 0;j < i;j ++)
        {
            if (a[j] < a[i]) sum ++;
        }
        cout << sum << ' ';
    }
    
    return 0;
}

B.最后一个签到 还是个字符串基础题

alt

直接用哈希表unordered_set储存字符串,自动去重,再用.size()计数

PS:unordered_set用.insert()插入数据。这题用set也行,还能自动排序

我的代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    unordered_set<string> S;
    int n;
    cin >> n;
    while (n --)
    {
        string a;
        cin >> a;
        S.insert(a);
    }
    cout << S.size();
}

C.送你们一个字符串的经典题吧

alt

经典中的经典,求KMP的next数组,证明背模板是多么的有用qwq

这个模板是从0开始的储存的字符串,要背好

我的代码:

#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

int ne[N];
int j;

int main()
{
    string s;
    cin >> s;
    for (int i = 1;i < s.size();i ++)
    {
        while (j && s[j] != s[i]) j = ne[j - 1];
        if (s[j] == s[i]) j ++;
        ne[i] = j;
    }
    for (int i = 0;i < s.size();i ++) cout << ne[i] << ' ';
    
    return 0;
}

D.交换机

alt alt

伪装了一下的并查集模板题,数据比较大,要用快读和longlong~

补题代码:

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务