首页 > 其他分享 >牛客小白月赛75

牛客小白月赛75

时间:2023-07-01 21:22:46浏览次数:37  
标签:std int ++ cin 牛客 75 小白月赛 x2 y2

A.上班

题意:


分析:

签到题

代码:

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

int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    
    cout << x + min(y, z);
    
    return 0;
}

B.崇拜

题意:


分析:

按知识点难度从大到小排序,然后计算按这个顺序讲解的最大崇拜值。

代码:

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

const int N = 2e5 + 5;
int a[N];

bool cmp(int A, int B)
{
    return A > B;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int n, x, y;
    cin >> n >> x >> y;
    
    for (int i = 0; i < n; i ++)
        cin >> a[i];
    
    sort(a, a + n, cmp);
    
    int res = 0, Max = -0x3f3f3f3f;
    
    for (int i = 0; i < n; i ++)
    {
        if (a[i] > y)
            res += 3;
        else if (a[i] < x)
            res --;
        Max = max(Max, res);
    }
    
    cout << max(0, Max);
    
    return 0;
}

C.方豆子

题意:



分析:

递归模拟一下就行了。

代码:

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

const int N = 3 * 1024 + 5;
char a[N][N];
char good[7][7] = {"******", "******", "******", "***...", "***...", "***..."};
char bad[7][7] = {"......", "......", "......", "...***", "...***", "...***"};

void setGood(int x, int y)
{
    for (int i = 0; i < 6; i ++)
        for (int j = 0; j < 6; j ++)
            a[x + i][y + j] = good[i][j];
}

void setBad(int x, int y)
{
    for (int i = 0; i < 6; i ++)
        for (int j = 0; j < 6; j ++)
            a[x + i][y + j] = bad[i][j];
}

void create(int x, int y, bool flag, int n)
{
    if (n == 1)
    {
        if (flag)
            setGood(x, y);
        else
            setBad(x, y);
        return;
    }
    
    int m = 3 * (1 << n);
    
    create(x, y, !flag, n - 1);
    create(x, y + m / 2, !flag, n - 1);
    create(x + m / 2, y, !flag, n - 1);
    create(x + m / 2, y + m / 2, flag, n - 1);
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    
    create(0, 0, 1, n);
    
    int m = 3 * (1 << n);
    
    for (int i = 0; i < m; i ++)
    {
        for (int j = 0; j < m; j ++)
        {
            cout << a[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

D.矩阵

题意:


分析:

由于只有相邻的元素互异才能移动,如果元素相同则修改,因此最终的路径一定是010101010……或者1010101010……交替。观察前面两种路径,我们可以发现,(x, y)处的元素与起点的元素满足一定条件:当哈夫曼距离为奇数时,(x,y)的元素与起点不同,当哈夫曼距离为偶数时,(x,y)的元素与起点相同。因此我们在搜索最短花费时,可以根据当前位置与起点的哈夫曼距离以及当前元素与起点元素是否相同来却确定节点之间的边权值,最后跑一边dijkstra即可。

代码:

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

#define x first
#define y second

const int N = 1010;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;

char g[N][N];
int d[N][N], dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bool st[N][N];
int n, m;

void dijkstra()
{
    memset(d, 0x3f, sizeof d);
    priority_queue<PIPII, vector<PIPII>, greater<PIPII>> heap;
    d[0][0] = 0;
    heap.push({0, {0, 0}});
    
    while (heap.size())
    {
        auto t = heap.top();
        heap.pop();
        int dist = t.x;
        PII ver = t.y;
        int x1 = ver.x, y1 = ver.y;
        
        if (st[x1][y1])
            continue;
        st[x1][y1] = true;
        
        for (int i = 0; i < 4; i ++)
        {
            int x2 = x1 + dx[i], y2 = y1 + dy[i];
            
            if (x2 < 0 || x2 >= n || y2 < 0 || y2 >= m)
                continue;
            
            int w;
            if ((x2 + y2) & 1)
            {
                if (g[x2][y2] == g[0][0])
                    w = 2;
                else
                    w = 1;
            }
            else
            {
                if (g[x2][y2] == g[0][0])
                    w = 1;
                else
                    w = 2;
            }
            
            if (d[x2][y2] > dist + w)
            {
                d[x2][y2] = dist + w;
                heap.push({d[x2][y2], {x2, y2}});
            }
        }
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    cin >> n >> m;
    
    for (int i = 0; i < n; i ++)
        cin >> g[i];
    
    dijkstra();
    
    cout << d[n - 1][m - 1];
    
    return 0;
}

E.数数

题意:


分析:

动态规划。
状态定义:f[i][j]表示放置了i个数,且前i个数的和为i * j的方案数。
状态转移:f[i + 1][k] += f[i][j],对于任意j使得1 ≤ (i + 1) × k - i × j ≤ m。
答案:\(\sum_{i=1}^m\)f[n][i]

代码:

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

const int N = 2010, mod = 1e9 + 7;
typedef long long LL;
LL f[N][N];

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    
    for (int i = 1; i <= m; i ++)
        f[1][i] = 1;
    
    for (int i = 1; i < n; i ++)
    {
        for (int j = 1; j <= m; j ++)
        {   
            for (int k = (i * j) / (i + 1) + 1; k <= m; k ++)
            {
                if ((i + 1) * k - i * j > m)
                    break;
                f[i + 1][k] = (f[i + 1][k] + f[i][j]) % mod;
            }
        }
    }
    
    LL ans = 0;
    for (int i = 1; i <= m; i ++)
        ans = (ans + f[n][i]) % mod;
    
    cout << ans;
    
    return 0;
}

标签:std,int,++,cin,牛客,75,小白月赛,x2,y2
From: https://www.cnblogs.com/scoxty/p/17519950.html

相关文章

  • CS7530CC支持PD3.0,双C口协议芯片,20-35W功率
    协议支持:1,USB电源PD3.0固定PDO2,USB电源PDPPSPDO3,支持20W~35WPDO配置4,USBTYPE-C,CC-逻辑5V/3A5,支持双口TypeC快速充电与单电源6,2kVHBM和1kVCDMESD静电防护等级7,40°C~+125°C工作温度,符合RoHS和无卤素快充协议芯片的作用:1、快速充电管理:快充协议芯片能够根据充电设备和电源......
  • 【牛客小白75】D 矩阵 【bfs+优先队列】
    题目https://ac.nowcoder.com/acm/contest/60063/D题意是说,给你一张\(n*m(n,m\leq10^3)\)大小的01地图,当前点下一步只能走到相邻的点上,如果这两个点值相同,则代价为2,否则代价为1,问从(1,1)走到(n,m)最少代价是多少思路首先很容易想到只往右下走是错的,有可能往左和往上走总代价更......
  • 牛客小白月赛75
    C方豆子题意按照题意模拟,详见链接思路看到的第一眼就想递归,之后发现稍微有点麻烦没那么直接难度不高,模拟水题代码//>>>Qiansui#include<map>#include<set>#include<list>#include<stack>#include<cmath>#include<queue>#include<deque>#include<cstdio&g......
  • CF1753 题解
    CF1753题解A首先我们发现,我们可以将序列一部分取反,将1变-1,-1变1的操作每次将总和增加2,所以如果初始和的绝对值为奇数则无解。我们发现,一段区间可以拆成若干个长度为2和1的小区间(+-+-+-+-....)变成(+-+-+-...)。我们假设初始都是长度为1的小区间,这时答案等于所有数的总和。我们......
  • P3975 [TJOI2015] 弦论 题解
    一、题目描述:给你一个长度为$n$的字符串,字符串由$26$个小写字母组成,求第$k$大的字串。给定参数$t$:$t=0:\位置不同的相同字串只算一个。$$t=1:\位置不同的相同字串算作多个。$若字串数量不足$k$个,输出$-1$。数据范围:$1\le......
  • 牛客图论 (第一章)
    F棋盘覆盖#include<bits/stdc++.h>usingnamespacestd;#definelllonglongconstintN=105,M=N*N*4,ID=N*N+N;intn,m;inthead[ID],ver[M],nxt[M],tot;boolban[N][N];intdx[]={1,-1,0,0},dy[]={0,0,1,-1};intmatch[ID];boolv[ID];......
  • 题解 P8757 [蓝桥杯 2021 省 A2] 完美序列
    题解P8757[蓝桥杯2021省A2]完美序列题意如果一个序列是单调递减的,而且除了第一个数以外的任何一个数都是上一个数的因数,则称这个序列为一个完美序列。一个序列中的一个子序列如果是完美序列,则称为该序列的一个完美子序列。一个序列的最长完美子序列长度,称为该序列的完美......
  • hdu 1575(矩阵快速幂)
    题解:矩阵快速幂模板题。#include<stdio.h>#include<string.h>constintN=10;structMat{intg[N][N];}res,ori;intn,k;Matmultiply(Matx,Maty){Mattemp;memset(temp.g,0,sizeof(temp.g));for(inti=0;i<n;i++)......
  • WP CTF-Web 攻防世界 GFSJ0475 get_post
    「场景」进入场景后提示请用GET方式提交一个名为a,值为1的变量「思路」根据提示在url后加上?a=1,回车发送请求。出现新提示。请再以POST方式随便提交一个名为b,值为2的变量打开brupsuite,配置本地代理为brupsuite中proxy的地址和端口号,刷新浏览器页面,brupsuite捕获到请求......
  • 牛客练习赛112 B qsgg and Subarray
    这里介绍两种解法,贪心和二分核心:只要某一个区间和为0,则所有包含该区间的和都为0贪心根据题意是求出所有⊕和为0的子区间的个数,我们按a[i]来分类,每次求出以a[i]为末尾,区间和为0的区间个数,对于a[i]来说,要想u~i的区间和为0,则需要包含所有a[i]中位为1都有0与之对应,如果u~i的区间和......