首页 > 其他分享 >牛客小白月赛100 A~E

牛客小白月赛100 A~E

时间:2024-10-13 11:49:20浏览次数:1  
标签:const int 小白月赛 nullptr long 牛客 ans tie 100

牛客小白月赛100 A~E

A-ACM中的A题

签到不多说

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
ll a[N],b[N];
int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
  
    for(int i = 1;i <= 3; i++)
        cin>>a[i];
    bool ok = false;
    for(int i = 1;i <= 3; i++)
    {
        int t = a[i];
        for(int j = 1;j <= 3; j++)
        {
            b[j] = a[j];
        }
        b[i] = t*2;
        sort(b+1,b+1+3);
        // cout<<b[1]<<" "<<b[2]<<" "<<b[3]<<"\n";
        if(b[1] + b[2] > b[3])
            ok = true;
    }
    if(ok)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

B-ACM中的C题

思路:我们知道肯定是没交互过的之间进行交互更优。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
ll a[N];
int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
  
    int n; cin>>n;
    for(int i = 1;i <= n; i++)
        cin>>a[i];

    ll ans = 0;
    if(n==1)ans = -1;
    else if(n==2)ans = 1;
    else if(n==3)ans = 2;
    else{
        ans = (n+1)/2;
    }
    cout<<ans<<"\n";
    return 0;
}

C-ACM中的M题

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int a[N],b[N];
vector<int>type[N];
map<int,int>mp;
int cnt = 0;
int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
  
    int n; cin>>n;
    for(int i = 1;i <= n; i++)
        cin>>a[i];
    for(int i = 1;i <= n; i++)
    {
        cin>>b[i];
        if(mp[b[i]] == 0)
            mp[b[i]] = ++cnt;
        type[mp[b[i]]].push_back(a[i]);
    }
    ll ans = 0;
    for(int i = 1;i <= cnt; i++)
    {
        if(type[i].size()==1)
        {
            ans = -1;
            break;
        }
        

        ans += (type[i].size()+1)/2;
    }

    cout<<ans<<"\n";


    return 0;
}

D-ACM中的AC题

无非就是三种情况:

  1. 我先到
  2. 镜像先到
  3. 一起到

其实本质上都是一种。

我们可以先做一个预处理,预处理出每一个出口到每一个点的最短距离。然后在做bfs,注意两个一起走,都不能越界和到陷阱里面。

因为是关于\(sx,sy\)对称的,因此可以通过我的\((x_1,y_1)\)推出镜像的(\(2 * sx - x_1,2*sy-x_2\))。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e3 + 10;

int n,m,sx,sy;
char a[N][N];

int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int ans = 1e9;
bool vis[N][N];
int dist[N][N];
bool in(int x,int y)
{
    return x >= 1 && x <= n && y >= 1 && y <= m;
}


void init()
{
    memset(dist,0x3f,sizeof(dist));
    queue<array<int,3>>q;
    for(int i = 1;i <= n; i++)
        for(int j = 1;j <= m; j++)if(a[i][j] == '@'){
            q.push({i,j,0});
            vis[i][j] = true;
        }

    while(!q.empty())
    {
        auto [x,y,d] = q.front();
        q.pop();

        dist[x][y] = d;
        for(int i = 0;i < 4; i++)
        {
            int dx = x + dir[i][0];
            int dy = y + dir[i][1];
            if(in(dx,dy) && a[dx][dy] != '#' && !vis[dx][dy]){
                vis[dx][dy] = true;
                q.push({dx,dy,d + 1});
            }
        }
    }
}



void bfs(int sx,int sy)
{
    memset(vis,false,sizeof(vis));
    queue<array<int,3>>q;
    q.push({sx,sy,0});
    vis[sx][sy] = true;
    while(!q.empty()){
        auto [x,y,d] = q.front();
        q.pop();
        if(a[x][y] == '@'){
            ans = min(ans,d + dist[2*sx-x][2*sy-y]);
        }

        for(int i = 0;i < 4; i++)
        {
            int dx1 = x + dir[i][0];
            int dy1 = y + dir[i][1];
            int dx2 = 2 * sx - dx1;
            int dy2 = 2 * sy - dy1;
            if(in(dx1,dy1) && in(dx2,dy2) && !vis[dx1][dy1] && a[dx1][dy1] != '#' && a[dx2][dy2] != '#'){
                vis[dx1][dy1] = true;
                q.push({dx1,dy1,d+1});
            }
        }
    }
}


int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    
    cin>>n>>m>>sx>>sy;

    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m; j++)
            cin>>a[i][j];
    init();

    bfs(sx,sy);
    if(ans == 1e9) ans = -1;
    cout<<ans<<"\n";
    return 0;
}

E-ACM中的CM题

思路:我们可以考虑枚举排雷能力。二分找到第一个大于pos+m的地方,不断往后跳,算贡献取min即可。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int n; cin>>n;
    for(int i = 1;i <= n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int ans = n;

    for(int m = 0;m < n; m++)
    {
        int t = m;
        int pos = a[1];
        while(1)
        {
            t++;
            pos = upper_bound(a+1,a+1+n,pos+m)-a;
            if(pos == n+1)break;
            pos = a[pos];
        }
        ans = min(ans,t);
    }
    cout<<ans<<"\n";
    return 0;
}

标签:const,int,小白月赛,nullptr,long,牛客,ans,tie,100
From: https://www.cnblogs.com/nannandbk/p/18462097

相关文章

  • 牛客小白月赛98 A~D
    牛客小白月赛98A~DA-骰子魔术签到不多说//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr),cout......
  • 牛客小白月赛99 C~E
    牛客小白月赛99C~EC-迷宫思路:其实能不能到达,只要看起点和终点是否能变成连通的。射线技能只能用一次,我们在起点能到的点\((x,y)\)去\(check:x,y,x-1,y-1,y+1\)是否在终点能到达的点的坐标中出现。//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;......
  • Python从0到100(六十三):Python OpenCV-入门基础知识
    前言:零基础学Python:Python从0到100最新最全教程。想做这件事情很久了,这次我更新了自己所写过的所有博客,汇集成了Python从0到100,共一百节课,帮助大家一个月时间里从零基础到学习Python基础语法、Python爬虫、Web开发、计算机视觉、机器学习、神经网络以及人工智能相关知......
  • 代码随想录Day24 | LeetCode 122. 买卖股票的最佳时机 II、LeetCode 55. 跳跃游戏、Le
    LeetCode122.买卖股票的最佳时机IIclassSolution:defmaxProfit(self,prices:List[int])->int:res=0foriinrange(1,len(prices)):res+=max(0,prices[i]-prices[i-1])returnresLeetCode55.跳跃游戏class......
  • 每日OJ题_牛客_比那名居的桃子_滑动窗口/前缀和_C++_Java
    目录牛客_比那名居的桃子_滑动窗口/前缀和题目解析C++代码Java代码牛客_比那名居的桃子_滑动窗口/前缀和比那名居的桃子(nowcoder.com)描述:        小红有一天看到了一只桃子,由于桃子看上去就很好吃,小红很想把它吃掉。已知吃下桃子后,每天可以获得ai​的......
  • 毕业设计项目-基于ssm+vue的外卖点餐系统+vue源码+10000字论文
    项目简介基于SSM实现的,主要功能如下:审核说明本项目源码收集于互联网或用户分享,经我们对资料的认真审核整理,确保资源可以正常使用;悉知:有一定的基础同学可以自行导入idea或者eclipse中运行项目,我们并不提供免费的技术指导。项目技术spring/springmvc/mybatis/(jsp)/html/......
  • 题解:牛客小白月赛102(A - C)
    A序列中的排列题意:每次给你两个正整数\(n,k\),并给你一段长度为\(n\)的序列。(所有输入均为小于等于100的正整数)问:原序列中是否存在子序列,使得这个子序列是\(k\)的排列子序列:某个序列的子序列是从最初序列通过去除某些元素但不破坏余下元素的相对位置(在前或在后)而形成的......
  • kubernetes 初始化集群 证书100年操作 【kubeadm】
    1、下载源码[root@SPHQBKCEK8SMS01~]#gitclonehttps://github.com/kubernetes/kubernetes#切换到自己的版本,修改源码,比如我的是v1.20.15版本[root@SPHQBKCEK8SMS01kubernetes]#cdkubernetes/[root@SPHQBKCEK8SMS01kubernetes]#gitcheckoutv1.20.15[root@SPHQBKCE......
  • 【gpt搬运】bash脚本压缩png,jpg图片,当图片大小大于100kb的时候
    可以编写一个Bash脚本,使用find命令查找图片文件并利用imagemagick或jpegoptim以及pngquant等工具来压缩图片。如果图片大小大于100KB,就进行压缩。下面是一个示例脚本:准备工具:安装imagemagick:用于转换图片格式安装jpegoptim:用于压缩.jpg图片安装pngquant:用于......
  • ### 100th 2024/9/8 WQS二分小结
    破百了,路长了这个世界,能听见我的回响吗?循环了很久很久的Echoism回望了过去,也要认真注视当下的现实了对吗?来看看WQS二分可以用上的题目有Raper,Gmoj的coffee和划分序列这几题都有一个共同的特点,就是要从n个中恰好选k个的极值而他们的取值都有一个共性,就是关于k,该函数的形状......