《看了受制了》第十九天,7道题,合计84道题

发布时间 2023-09-17 22:55:38作者: wxzcch

2023年9月17日

今天晚上打了牛客的周赛。题目不是很难的题目,哎,最后一题是位运算,不会啊。。。异或和。。
今晚还发现了一个up主,同是21级,大二摘金,我大二哎。每次都会感到世界的层次,认识到自己的弱小。。。而且也发现自己的一些观念上的错误。

牛客周赛12 小美种树

题目理解

这个题和之前蓝桥杯那个期末作业是一个道理。

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
    
    ll x, y, z;
    cin >> x >> y >> z;
    
    ll week = (z / (3 * x + y));
    
    z -= week * (3 * x + y);
    
    if(z == 0)
        cout << week * 3;
    else{
        
        int day = 0;
        int k = 0;
        while(z > 0)
        {
            if(k == 0)
                z -= x + y;
            else
                z -= x;
            day++;
            k++;
        }
        cout << week * 3 + day;
    }
    
    return 0;
}

牛客周赛12 小美的子序列

题目理解

这个题就是遍历每个序列看能不能找到某个字母,但一定是顺序的。每次找到一个就让标签往后移一个,最后如果是7那么就一定找到了。

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
    
    int n, m;
    cin >> n >> m;
    
    string st = "meituan";
    int k = 0;
    
    for(int i = 0; i < n; i++)
    {
        
        string b;
        cin >> b;
        for(int j = 0 ; j < m; j++)
        {
            if(b[j] == st[k] && k < 7)
            {
                k++;
                break;
            }
        }
        
    }
    
    if(k == 7)
        cout << "YES";
    else
        cout << "NO";
    
    return 0;
}

牛客周赛12 小美的游戏

题目理解

先排个序,然后倒着乘,就是最大的。

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

const int N = 1e5 + 10, Mod = 1e9 + 7;
int n, k;

ll a[N];

int main()
{
    
    cin >> n >> k;
    
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    
    sort(a + 1, a + 1 + n);
    
    for(int j = n, i = k; i >= 1; i--, j--)
    {
        a[j - 1] = (a[j] * a[j - 1]) % Mod;
        a[j] = 1;
    }
    
    ll res = 0;
    for(int i = 1; i <= n; i++)
        res = (res + a[i]) % Mod;
    
    cout << res;
    
    return 0;
}

牛客小白周赛3 游游的七倍数

题目理解

乘10之后,向上取整除7,再乘7即可。

代码实现

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

ll n, m;

int main()
{
    cin >> n;
    
    n = n * 10;
    
    ll t = ceil(1.0 * n / 7);
    
    cout << t * 7;
    return 0;
}

牛客周赛3 游游的字母串

题目理解

枚举,全变成每一个字母的成本。成本取min(abs(j - (int)s[i]), 26 - abs(j - (int)s[i])),因为是一个循环所以从az有两种情况,第一种是25步,第二种是26 - 25步。取小的即可

代码实现

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

string s;
const int N = 30;

int a[N];


int main()
{
    cin >> s;
    
    
    for(int i = 0 ; i < s.size(); i++)
    {
        for(int j = 97; j <= 97 + 25; j++)
        {
            int t = abs(j - (int)s[i]);
            
            a[j - 96] += min(26 - t, t);
        }
    }
    
    int res = a[1];
    for(int i = 1; i <= 26; i++)
        res = min(res, a[i]);
    
    cout << res;
    return 0;
}

牛客周赛3 游游的水果大礼包

题目理解

枚举第一个礼包,然后求第二个礼包。枚举每一个答案即可。

代码实现

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;


int main()
{
    ll n, m, a, b;
    cin >> n >> m >> a >> b;
    ll res = 0;

    // 一号礼包
    for(int i = 0 ; i * 2 <= n && i <= m; i++)
    {
        // 二号礼包
        int j = min(n - 2 * i, (m - i) / 2);
        
        res = max(res, i * a + j * b);
       
    }

    cout << res;
    return 0;
}

牛客周赛3 游游的矩阵权值

题目理解

可以得出以下规律:

  • 四个角会被计算2
  • 四个边上除四个角以外的块,会被计算3次。
  • 其他块都是4

随后便可用等差求和公式得出结果。这个题目中,还学到了大佬的很多模板!!!很牛逼!

代码实现

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;

const int Mod = 1e9 + 7;

ll n;

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1) res = res * a % Mod;
        a = a * a % Mod;
        b >>= 1;
    }
    return res;
}

ll inv(ll x){ return qmi(x, Mod - 2);}

ll mo(ll x){ return (x % Mod + Mod) % Mod;}

ll sum(ll l, ll r)
{ 
    return (l + r) % Mod * mo(r - l + 1) % Mod * inv(2) % Mod;
}

int main()
{
    
    cin >> n;
    ll res = 0;
    
    res = 2 * sum(1, 4);
    res = mo(res + 3 * sum(5, 5 + 4 * (n - 2) - 1));
    res = mo(res + 4 * sum(5 + 4 * (n - 2), n * n));
    
    cout << res;
    return 0;
}