牛客周赛 Round 38

牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)

A-小红的正整数自增_牛客周赛 Round 38 (nowcoder.com)

取出最后一位判断即可 

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;

void solve()
{
    string s;
    cin >> s;
    char ch = s.back();
    int x = (ch ^ 48);
    x = 10 - x;
    cout << (x == 10 ? 0 : x);
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

 

B-小红的抛弃后缀_牛客周赛 Round 38 (nowcoder.com) 

小红拿到了一个正整数,她准备切掉一个后缀并抛弃,使得剩余部分是9的倍数。小红想知道有多少种不同的操作方案? 

因为删除的后缀是连续的,即有多少前缀满足是9的倍数,从前往后O(n)判断即可

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;

void solve()
{
	string s;
    cin >> s;
    int sum = 0;
    int ans = 0;
    for(auto &x : s)
    {
        sum = sum * 10 + (x ^ 48);
        if(sum % 9 == 0)ans += 1;
        sum %= 9;
    }
    cout << ans;
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

C-小红的字符串构造_牛客周赛 Round 38 (nowcoder.com) 
小红希望你构造一个长度为nnn的、仅包含小写字母的字符串,其中恰好有kkk个长度大于1的回文子串。你能帮帮她吗 

 有2种方式:因为k <= n / 2

所以可以通过前k个由2个相同字符(a -> z轮流输出),后 n - 2k个乱序即可

我的方式是先用前几个字符找到可达到的最大值,挨个靠近,最后的剩下的乱序,这样k可以不局限于k <= n / 2,k可以取n个字符能达到的最多回文数

// Problem: 小红的字符串构造
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78292/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;
/*
aa   1
aaa  3 
aaaa 6 
aaaaa 10 
*/
string s = "qwertyuiopasdfghjklzxcvbnm";
void solve()
{
	cin >> n >> k;
	int pos = 0;
	int t = 0;
	while(k)
	{
		k--; t+=2;
		cout << s[pos] << s[pos];
		int cnt = 2;
		while(k >= cnt)
		{
			cout << s[pos];
			k -= cnt;
			cnt++;
			t++;
		}
		pos = (pos + 1) % 26;
	}
	//cout <<"T = " << t << endl;
	for(int i = 1; i <= n - t;i++)
	{
		cout << (s[(pos + i) % 26]);
	}
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

D-小红的平滑值插值_牛客周赛 Round 38 (nowcoder.com) 

显然该题最终只有3个情况

情况1:最大平滑值 == k,无需操作

情况2:最大平滑值 < k,可证明最多只需一次操作,随便列一组数据即可:如k取7

最大平滑值取 任意x < 7,即任意1 < =i < j <= n abs(a[j] - a[i])< 7

1 7 ==> 在1后面插入一个 8 即可

1 3 == > 依旧插入一个8即可

显而易见若最大平滑值abs(a[x] - a[y] ) < k == > 在a[x] a[y]中间插入a[x] + k即可

情况3:最大平滑值 > k

在每一个平滑值大于k的数中间插入一个大小为x,首项为a[X] + k,d = k的等差数列,其中x = a[y] /a[x]向下取整

特例若可以整除需要减1 ,原因最后一项大小 == a[y]因此无需插入 

 

// Problem: 小红的平滑值插值
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78292/D
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;
int a[maxn];
int pos = 0;
int fun(int a, int b)
{
	return a % b == 0 ? a / b - 1 :a / b;
}

void solve()
{
	cin >> n >> k;
	for(int i = 1;i <= n;i++)
	cin >> a[i];
	int mk = 0;
	int ans = 0;
	for(int i = 2;i <= n;i++)
	{
		int t = abs(a[i] - a[i - 1]);
		if(t > k)
		{
			ans += fun(t, k);
		}
		mk = max(mk, t);
	}
	if(mk == k)cout << 0;
	else if(mk > k)cout << ans;	
	else cout << 1;
	
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

E-小苯的等比数列_牛客周赛 Round 38 (nowcoder.com) 

暴力枚举即可

// Problem: 小苯的等比数列
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78292/E
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
//#define for(a -> b) for(int i = a; i <= b;i++)
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, T = 1, A, B;
vector<int>v;
int M[maxn];
int cnt[maxn];

void solve()
{
	cin >> n;
	int ans = 0;
	for(int i = 1;i <= n;i++)
	{
		cin >> m;
		M[m] += 1;
		ans = max(ans, M[m]);
	}
	for(int i = 1; i <= 2e5; i++)
	{
		if(M[i])
		for(int j = 2; i * j <= 2e5; j++)
		{
			int cnt = 1;
			if(M[i * j])
			{
				for(int k = i * j; k <= 2e5; k *= j)
				{
					if(M[k])ans = max(ans, ++cnt);
					else break;
				}
			}
		}
	}
	cout << ans << endl;
}


signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

F-小苯的回文询问_牛客周赛 Round 38 (nowcoder.com) 

因为是不连续的,因此每一次对于M[a[i]]的更新即是最后一次出现a[i]的位置 

我们只需要找到最近可满足的坐标

当查找区间l r时,我们通过找到r位置最近可以形成回文的位置,若其大于等于l说明该区间有子区间满足不连续的回文串,其中如果dp[r] = 0说明没有回文串可形成

    // Problem: 小苯的回文询问
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/78292/F
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA cout << "SHU_YUAN" << endl;
const int maxn = 1e6 + 10;
int n, m, k, d, q, T = 1, A, B;
int a[maxn],dp[maxn];//第i位往前最近可构成回文的坐标
map<int,int>M;
void solve()
{
	cin >> n >> q;
	for(int i = 1;i <= n;i++)cin >> a[i];
	for(int i = 1;i <= n;i++)
	{
		dp[i] = max(dp[i - 1], M[a[i]]);
		if(i - 1)M[a[i - 1]] = i - 1;
	}
	while(q--)
	{
		int l, r;
		cin >> l >> r;
		cout << (dp[r] >= l ? "YES" : "NO") << endl;
	}
}

signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/496982.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

46.continue语句

目录 一.continue语句 二.视频教程 一.continue语句 continue语句的作用和break语句很像&#xff0c;break语句会跳出当前循环&#xff0c;而continue语句则是跳出本次循环&#xff0c;继续执行下一次循环。 举个例子&#xff1a; #include <stdio.h>void main(void)…

想学网络安全,从哪里开始?网络安全的学习路线

网络安全学习路线&#xff1a; 想学习网络安全专业的知识&#xff0c;想当黑客&#xff0c;但是不知道该从哪里开始学。 我给你一个路线&#xff01; 清晰图片和大纲&#xff1a;https://docs.qq.com/doc/DU1lpVFpSbWVrd2p3

【每周精选资讯 | 第 1 期】2024-03-11 ~ 2024-03-17

前言 大家好&#xff0c;我是翼同学。这里是【每周精选资讯】的第一期内容。 GPT 递给我苹果 Figure展示了与OpenAI合作的最新进展&#xff0c;通过结合先进的神经网络&#xff0c;使机器人能够执行类似人类的快速、灵巧动作。主要功能包括描述周围环境、常识推理、将高层次…

Android ImageView以及实现截图

实现效果 截图前 截图后 代码 package cn.jj.huaweiad;import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; import android.view.ViewGro…

螺旋矩阵的算法刷题

螺旋矩阵的算法刷题 本文主要涉及螺旋矩阵的算法 包括三个题目分别是 59. 螺旋矩阵 II54. 螺旋矩阵 中等LCR 146. 螺旋遍历二维数组 文章目录 螺旋矩阵的算法刷题一 、螺旋矩阵简单1.1 实现一&#xff08;我认为这个方法更巧妙&#xff01;&#xff01;&#xff09;1.2 实现二&…

Redis入门到实战-第十七弹

Redis实战热身t-digest篇 完整命令参考官网 官网地址 声明: 由于操作系统, 版本更新等原因, 文章所列内容不一定100%复现, 还要以官方信息为准 https://redis.io/Redis概述 Redis是一个开源的&#xff08;采用BSD许可证&#xff09;&#xff0c;用作数据库、缓存、消息代理…

2024最新华为OD机试试题库全 -【二叉树计算】- C卷

1. 🌈题目详情 1.1 ⚠️题目 给出一个二叉树如下图所示: 请由该二叉树生成一个新的二叉树,它满足其树中的每个节点将包含原始树中的左子树和右子树的和。 左子树表示该节点左侧叶子节点为根节点的一颗新树;右子树表示该节点右侧叶子节点为根节点的一颗新树。 1.2 �…

自养号测评,补单的五大关键要素

现在很多大卖都是自己管理几百个账号&#xff0c;交给服务商不是特别靠谱 第一 你不知道服务商账号质量怎么样 第二 账号一天下了多少你也不清楚&#xff0c;如果下了很多单万一封号被关联了怎么办 第三 你也不知道服务商用什么卡给你下单&#xff0c;用一些低汇率和黑卡下单…

运用开关量信号远程传输装置实现工厂智能化技改需要分几步走

DTD509H系列开关量信号无线传输器由一个无线信号发射终端和一个无线信号接收终端组成&#xff0c;也可以根据用户现场实现一点对多点或者多点对一点的无线控制。DTD509H系列开关量信号无线传输器可与PLC的IO端口、继电器、二次仪表、传感器等工业设备配套使用&#xff0c;运用无…

【前端Vue】社交信息头条项目完整笔记第2篇:二、登录注册,准备【附代码文档】

社交媒体-信息头条项目完整开发笔记完整教程&#xff08;附代码资料&#xff09;主要内容讲述&#xff1a;一、项目初始化使用 Vue CLI 创建项目,加入 Git 版本管理,调整初始目录结构,导入图标素材,引入 Vant 组件库,移动端 REM 适配,关于 , 配置文件,封装请求模块。十、用户关…

快速上手Spring Cloud 十四:璀璨物联网之路

快速上手Spring Cloud 一&#xff1a;Spring Cloud 简介 快速上手Spring Cloud 二&#xff1a;核心组件解析 快速上手Spring Cloud 三&#xff1a;API网关深入探索与实战应用 快速上手Spring Cloud 四&#xff1a;微服务治理与安全 快速上手Spring Cloud 五&#xff1a;Spring …

Java项目:78 springboot学生宿舍管理系统的设计与开发

作者主页&#xff1a;舒克日记 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文中获取源码 项目介绍 系统的角色&#xff1a;管理员、宿管、学生 管理员管理宿管员&#xff0c;管理学生&#xff0c;修改密码&#xff0c;维护个人信息。 宿管员管理公寓…

iOS - Runtime-API

文章目录 iOS - Runtime-API1. Runtime应用1.1 字典转模型1.2 替换方法实现1.3 利用关联对象给分类添加属性1.4 利用消息转发机制&#xff0c;解决方法找不到的异常问题 2. Runtime-API2.1 Runtime API01 – 类2.1.1 动态创建一个类&#xff08;参数&#xff1a;父类&#xff0…

轻松赚钱,精彩生活:上班族副业赚钱新攻略大揭秘!

薪水总是捉襟见肘&#xff0c;每月账单总让人倍感压力。你是否曾在静谧的夜晚&#xff0c;躺在床上&#xff0c;思索如何为家庭多赚一分钱&#xff1f;其实&#xff0c;你并不孤单。在这个充满机遇与挑战的时代&#xff0c;越来越多的人开始寻找副业&#xff0c;以期望让生活更…

Appium设备交互API

设备交互API指的是操作设备系统中的一些固有功能&#xff0c;而非被测程序的功能&#xff0c;例如模拟来电&#xff0c;模拟发送短信&#xff0c;设置网络&#xff0c;切换横竖屏&#xff0c;APP操作&#xff0c;打开通知栏&#xff0c;录屏等。 模拟来电 make_gsm_call(phon…

八数码问题

八数码难题 题目描述 在 3 3 3\times 3 33 的棋盘上&#xff0c;摆有八个棋子&#xff0c;每个棋子上标有 1 1 1 至 8 8 8 的某一数字。棋盘中留有一个空格&#xff0c;空格用 0 0 0 来表示。空格周围的棋子可以移到空格中。要求解的问题是&#xff1a;给出一种初始布局…

Java项目:79 springboot海滨体育馆管理系统的设计与实现

作者主页&#xff1a;源码空间codegym 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文中获取源码 项目介绍 体育馆管理系统主要实现了管理员功能模块和学生功能模块两大部分 管理员功能模块&#xff1a; 管理员登录后可对系统进行全面管理操作&#…

内网穿透_ICMP_icmpsh

目录 一、ICMP协议详解 二、ICMP隧道 (一) 为什么会使用ICMP (二) 实验环境 (三) 操作流程 1. 下载icmpsh 2. 下载并安装依赖 3. 关闭本地icmp响应 4. 攻击机启动服务端开始监听 5. 靶机启动工具客户端 6. 攻击机接受到靶机传来的数据 三、郑重声明 一、ICMP协议详…

LeetCode_1.两数之和

一、题目描述 二、方法 1.方法1&#xff08;暴力枚举法&#xff09; 利用两个for循环&#xff0c;对数组进行逐一的遍历&#xff0c;直到找到两个数的和为目标值时返回这两个数的下标。以下为c实现的完整代码。 # include<iostream> using namespace std; #include<…

C语言分支循环语句详解

分支和循环语句是什么 在我们写程序的时候&#xff0c;总会遇到想一直循环执行某种语句的时候&#xff0c;这时候我们就要使用一种语句叫循环语句&#xff0c;或者带一些判断条件的语句&#xff0c;在C语言中提供了像这些的循环语句和分支语句 if else 语句 这是一种判断语句…
最新文章