Codeforces Round #894 (Div.3)

news2025/1/19 17:21:34

在这里插入图片描述

文章目录

  • 前言
  • A. Gift Carpet
    • 题目:
    • 输入:
    • 输出:
    • 思路:
    • 代码:
  • B. Sequence Game
    • 题目:
    • 输入:
    • 输出:
    • 思路:
    • 代码:
  • C. Flower City Fence
    • 题目:
    • 输入:
    • 输出:
    • 思路:
    • 代码:
  • D. Ice Cream Balls
    • 题目:
    • 输入:
    • 输出:
    • 思路:
    • 代码:
  • E. Kolya and Movie Theatre
    • 题目:
    • 输入:
    • 输出:
    • 思路:
    • 代码:
  • 总结


前言

昨天晚上打了一场Codeforces Div3 唉 打的很不好,只AC了两道思维题目。

在这里插入图片描述


A. Gift Carpet

题目:

链接:A. Gift Carpet
最近,Tema和Vika庆祝了家庭日。他们的朋友阿里娜给了他们一块地毯,可以表示为n⋅m
小写拉丁字母表。

维卡还没有看到礼物,但特玛知道她喜欢什么样的地毯。维卡会喜欢地毯,如果她能读上她的名字。她从左到右逐列阅读,并从当前列中选择一个或多个或零个字母。

从形式上讲,如果可以按从左到右的顺序选择四列不同的列,例如第一列包含“v”,第二列包含“i”,第三列包含“k”,第四列包含“a”,女孩会喜欢地毯。

帮助特玛提前了解维卡是否会喜欢艾琳娜的礼物。

输入:

每个测试由多个测试用例组成。输入的第一行包含单个整数t
(1≤t≤100) — 测试用例的数量。然后是测试用例的说明。

每个测试用例的第一行包含两个整数n,m
(1≤n,m≤20) — 地毯的尺寸。

下一个n行包含m每个小写拉丁字母,描述给定的地毯。

输出:

对于每组输入数据,如果 Vika 喜欢地毯,则输出“YES”,否则输出“NO”。
您可以以任何大小写(小写或大写)输出每个字母。例如,字符串“yEs”、“yes”、“Yes”和“YES”将被接受为肯定答案。
在这里插入图片描述

思路:

控制行和列的for循环互换,然后一列一列的去找,找到就k++然后跳出去下一列
最后如果k==4 就是输出yes否则就是输出no即可。

tip:唉 继续加油!!!

代码:

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		char s[22][22];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				cin>>s[i][j];	
			}
		}
		int k=0;
		for(int i=k;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(s[j][i]=='v')
				{
					if(k==0) 
					{
						k++;
						break;
					}
				}
				if(s[j][i]=='i')
				{
					if(k==1)
					{
						k++;
						break;
					}
				}
				if(s[j][i]=='k')
				{
					if(k==2)
					{
						k++;
						break;
					}
				}
				if(s[j][i]=='a')
				{
					if(k==3)
					{
						k++;
						break;
					}
				}
			}
		}
		if(k==4) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

B. Sequence Game

题目:

链接:B. Sequence Game
Tema and Vika are playing the following game.

First, Vika comes up with a sequence of positive integers a
of length m
and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence b
according to the following rule:

First, she writes down a1
Then, she writes down only those ai (2≤i≤m) such that ai−1≤ai
Let the length of this sequence be denoted as n

For example, from the sequence a=[4,3,2,6,3,3]
Vika will obtain the sequence b=[4,6,3]

She then gives the piece of paper with the sequence b
to Tema. He, in turn, tries to guess the sequence a

Tema considers winning in such a game highly unlikely, but still wants to find at least one sequence a
that could have been originally chosen by Vika. Help him and output any such sequence.

Note that the length of the sequence you output should not exceed the input sequence length by more than two times.

大概意思:

就是输入一个数组b,大小为n然后推测数组a里面的数字
推测的依据是:

  • 先写出来一个a[1];
  • 然后如果a[i-1]<a[i]的话就存放到b数组里面

题目也是让你从b—>a,用b推出a数组酱紫

输入:

Each test consists of multiple test cases. The first line of input data contains a single integer t (1≤t≤104) — the number of test cases. This is followed by a description of the test cases.

The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the sequence b

The second line of each test case contains n
integers b1,b2,b3,…,bn (1≤bi≤10^9) — the elements of the sequence.

The sum of the values of n over all test cases does not exceed 2⋅10^5

输出:

For each test case, output two lines. In the first line, output a single integer m
— the length of the sequence (n≤m≤2⋅n). In the second line, output m integers a1,a2,a3,…,am (1≤ai≤109) — the assumed sequence that Vika could have written on the first piece of paper.

If there are multiple suitable sequences, you can output any of them.

在这里插入图片描述

思路:

emm勉强可以说是双指针算法吧,就是开一个result数组存放需要添加的内容,然后设置一个m=0指针去添加数据就行了

核心地方就是当遇到降序的时候:直接添加一个数字1解决所有问题,就这样…

代码:

#include<iostream>
using namespace std;
 
int n,a[200005],m,b[400005];

int main()
{
	int t;
	scanf("%d\n",&t);
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		m=0;
		b[++m]=a[1];
		for(int i=2;i<=n;i++)
		{
			if(a[i]<a[i-1]) b[++m]=1;
			b[++m]=a[i];
		}
		printf("%d\n",m);
		for(int i=1;i<=m;i++) printf("%d ",b[i]);
		puts("");
	}
	return 0;
}

C. Flower City Fence

链接:C. Flower City Fence

题目:

Anya lives in the Flower City. By order of the city mayor, she has to build a fence for herself.
The fence consists of nplanks, each with a height of aimeters. According to the order, the heights of the planks must not increase. In other words, it is true that ai≥aj for all i<j.

Anya became curious whether her fence is symmetrical with respect to the diagonal. In other words, will she get the same fence if she lays all the planks horizontally in the same order.

For example, for n=5, a=[5,4,3,2,1], the fence is symmetrical. Because if all the planks are laid horizontally, the fence will be [5,4,3,2,1], as shown in the diagram.

在这里插入图片描述
But for n=3, a=[4,2,1], the fence is not symmetrical. Because if all the planks are laid horizontally, the fence will be [3,2,1,1], as shown in the diagram.

在这里插入图片描述
Help Anya and determine whether her fence is symmetrical.

输入:

The first line of the input contains an integer t (1≤t≤104) — the number of test cases.

The description of the test cases follows.

The first line of a test case contains a single integer n (1≤n≤2⋅105) — the length of the fence.

The second line of a test case contains n integers a1≥a2≥a3≥⋯≥an (1≤ai≤109) — the heights of the planks.

The sum of the values of n for all test cases does not exceed 2⋅105.

输出:

For each test case, output “YES” if the fence is symmetrical, otherwise output “NO”.

You can output each letter in any case (lowercase or uppercase). For example, the strings “yEs”, “yes”, “Yes” and “YES” will be accepted as a positive answer.

在这里插入图片描述

思路:

题目大意就是给你一个数组让你把这个数组抽象成长方体然后组合在一起,然后从对角线切分看是否关于切割线对称,如果对称就输出YES 否则 输出NO

算法标签:思维题

其实解决思路就是 a[a[i]]这个方法,其实a[a[i]]完美的解决了对称的问题,真的很不错,仔细想想是不是呢???
确实是这样的。

代码:

#include<stdio.h>

int a[200005];

void solve()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	for(int i=1;i<=n;++i)
	{
		if(a[i]>n || a[a[i]]<i) 
		{
			puts("No");
			return;
		}
	}
	puts("Yes");
	return;
}
int main()
{
	int t;
	scanf("%d",&t);
	
	while(t--) solve();
	
	return 0;
}

D. Ice Cream Balls

题目:

链接:D. Ice Cream Balls
Tema decided to improve his ice cream making skills. He has already learned how to make ice cream in a cone using exactly two balls.

Before his ice cream obsession, Tema was interested in mathematics. Therefore, he is curious about the minimum number of balls he needs to have in order to make exactly ndifferent types of ice cream.

There are plenty possible ice cream flavours: 1,2,3,…. Tema can make two-balls ice cream with any flavours (probably the same).

Two ice creams are considered different if their sets of ball flavours are different. For example, {1,2}={2,1}, but {1,1}≠{1,2}.

For example, having the following ice cream balls: {1,1,2}, Tema can make only two types of ice cream: {1,1} and {1,2}

Note, that Tema do not need to make all the ice cream cones at the same time. This means that he making ice cream cones independently. Also in order to make a following cone {x,x} for some x, Tema needs at least 2 balls of type x

Help Tema answer this question. It can be shown that answer always exist.

输入:

Each test consists of multiple test cases. The first line of input contains a single integer t (1≤t≤104) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains a single integer n (1≤n≤1018) — the number of ice cream types that Tema wants to make.

输出:

For each test case, output a single integer — the minimum number of balls Tema needs to buy.
在这里插入图片描述

思路:

可以抽象成为一个二叉树,就是一种雪糕必须有两种数字组合,然后我就蒙了哈哈哈,看大佬的代码大佬应该是总结出来了规律然后利用数学知识写出来了,反正我太菜了…对不起佬们

代码:

#include<iostream>
#include<cmath>

using namespace std;

int a[200005];

void solve()
{
	long long n;
	cin>>n;
	
	long long p=(1+sqrt(n*8+1))/2;
	cout<<p+n-p*(p-1)/2<<endl;
	
	return;
}

int main()
{
	long long t;
	cin>>t;
	
	while(t--) solve(); 
	
	return 0;
}

E. Kolya and Movie Theatre

链接:E. Kolya and Movie Theatre

题目:

Recently, Kolya found out that a new movie theatre is going to be opened in his city soon, which will show a new movie every day for n days. So, on the day with the number 1≤i≤n, the movie theatre will show the premiere of the i-th movie. Also, Kolya found out the schedule of the movies and assigned the entertainment value to each movie, denoted by ai

However, the longer Kolya stays without visiting a movie theatre, the larger the decrease in entertainment value of the next movie. That decrease is equivalent to d⋅cnt, where d is a predetermined value and cnt is the number of days since the last visit to the movie theatre. It is also known that Kolya managed to visit another movietheatre a day before the new one opened — the day with the number 0. So if we visit the movie theatre the first time on the day with the number i, then cnt — the number of days since the last visit to the movie theatre will be equal to i

For example, if d=2 and a=[3,2,5,4,6], then by visiting movies with indices 1 and 3, cnt value for the day 1 will be equal to 1−0=1 and cnt value for the day 3 will be 3−1=2, so the total entertainment value of the movies will be a1−d⋅1+a3−d⋅2=3−2⋅1+5−2⋅2=2.

Unfortunately, Kolya only has time to visit at most m movies. Help him create a plan to visit the cinema in such a way that the total entertainment value of all the movies he visits is maximized.

输入:

Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers n, m, and d (1≤n≤2⋅105, 1≤m≤n, 1≤d≤109).

The second line of each set of input data contains n integers a1,a2,…,an (−109≤ai≤109) — the entertainment values of the movies.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

输出:

For each test case, output a single integer — the maximum total entertainment value that Kolya can get.

在这里插入图片描述

思路:

算法标签:贪心算法

利用优先队列(priority_queue)的用法进行编写代码,优先队列的知识点:C++中优先队列的priority_queue<int,vector<int>,greater<int>>与priority<int>的用法

主要用优先队列存放大于0的元素,然后除了第一个数据后的每m个数据就可以存放到记录数组里面,最后遍历找价值最大的即可

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
 
int n,m,d,a[200005],b[200005];
 
void solve()
{
	priority_queue<int,vector<int>,greater<int> >q;
	cin>>n>>m>>d;
	for(int i=1;i<=n;i++) cin>>a[i];
	int s=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			s+=a[i];
			q.push(a[i]);
			while(q.size()>m) s-=q.top(),q.pop();
		}
		b[i]=s;
	}
	for(int i=1;i<=n;i++) ans=max(ans,b[i]-d*i);
	cout<<ans<<endl;
}
 
signed main()
{
	int t;
	scanf("%lld\n",&t);
	while(t--) solve();
	return 0;
}

总结

第二次打CF Div3 比起大一寒假那次多写出来一道思维题,也算是有点点进步吧,今天早上起来锻炼完身体后就开始补题,把我蹦一蹦能够到的"桃子"给摘下来进行学习,虽然打的时候很坐牢,但是成长后的感觉真的很不错,慢慢进步慢慢比赛总会有一天你会变强的,加油夏目浅石.

在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

keepalived双机热备 (四十五)

一、概述 Keepalived 是一个基于 VRRP 协议来实现的 LVS 服务高可用方案&#xff0c;可以解决静态路由出现的单点故障问题。 原理 在一个 LVS 服务集群中通常有主服务器&#xff08;MASTER&#xff09;和备份服务器&#xff08;BACKUP&#xff09;两种角色的服务器…

nuxt2-storybook-vite:环境搭建、基础使用 / nuxt项目组件库

一、创建 nuxt2 项目 安装 - NuxtJS | Nuxt.js 中文网 yarn create nuxt-app <项目名> 二、安装 storybook 2.1、初始化 Storybook pnpm add -g storybook/cli npx -p storybook/cli sb init 命令解释 序号命令命令解释1npx -p storybook/cli sb init是一个命令行…

基于JSP+Servlet+mysql员工权限管理系统

基于JSPServletmysql员工权限管理系统 一、系统介绍二、功能展示四、其他系统实现五、获取源码 一、系统介绍 项目类型&#xff1a;Java web项目 项目名称&#xff1a;基于JSPServlet的员工权限管理系统[qxxt] 项目架构&#xff1a;B/S架构 开发语言&#xff1a;Java语言 …

【ag-grid-vue】column

网格中的每一列都使用列定义(ColDef)来定义。列根据在网格选项中指定的列定义的顺序在网格中定位。 列定义 下面的例子展示了一个定义了3列的简单网格: <template><ag-grid-vuestyle"height: 300px; width: 1000px"class"ag-theme-balham":colum…

最新外卖点餐微信小程序源码系统 完整前后端+安装部署教程

分享一个完整的外卖点餐微信小程序源码系统&#xff0c;含完整代码程序包和详细的安装搭建教程。 系统为多用户&#xff0c;可以无限多开&#xff0c;轻松帮助商家开发各种外卖点餐小程序。系统功能特别强大。 小程序源码下载地址&#xff1a;春哥技术博客获取

python SystemRDL 包介绍

对于芯片验证&#xff0c;在验证寄存器环节&#xff0c;如果我们需要根据大量的寄存器来构建我们的sequence或者激励&#xff0c;比如irq测试&#xff0c;我们需要测试irq信号源到寄存器门口的连接是否正常&#xff0c;irq 寄存器各个field的接线排序是否有弄错&#xff0c;以及…

Linux常用命令——dhcpd命令

在线Linux命令查询工具 dhcpd 运行DHCP服务器。 语法 dhcpd [选项] [网络接口]选项 -p <端口> 指定dhcpd监听的端口 -f 作为前台进程运行dhcpd -d 启用调试模式 -q 在启动时不显示版权信息 -t 简单地测试配置文件的语法是否正确的&#xff0c;但不会尝试执行任何网络…

五度易链最新“产业大数据服务解决方案”亮相,打造数据引擎,构建智慧产业!

自2015年布局产业大数据服务行业以来&#xff0c;“五度易链”作为全国产业大数据服务行业先锋企业&#xff0c;以“让数据引领决策&#xff0c;以智慧驾驭未来”为愿景&#xff0c;肩负“打造数据智能引擎&#xff0c;构建智慧产业新生态”的使命&#xff0c;坚持着精益生产、…

地下水资源监控中应用的深水液位传感器

地下水是水资源重要的组成部分,虽属可再生资源,但地下水更新和自净非常缓慢,一旦被污染,所造成的环境与生态破坏,往往长时间难以逆转。目前中国90%的城市地下水遭受污染,已呈现由点向面扩展的趋势。因此,加强对地下水的监控和相应技术的开发成为一种迫切需要。 环境监测是环境…

大数据(一)定义、特性

大数据&#xff08;一&#xff09;定义、特性 本文目录&#xff1a; 一、写在前面的话 二、大数据定义 三、大数据特性 3.1、大数据的大量 (Volume) 特性 3.2、大数据的高速(Velocity)特性 3.3、大数据的多样化 (Variety) 特性 3.4、大数据的价值 (value) 特性 3.5、大…

Linux下套接字TCP实现网络通信

Linux下套接字TCP实现网络通信 文章目录 Linux下套接字TCP实现网络通信1.引言2.具体实现2.1接口介绍1.socket()2.bind()3.listen()4.accept()5.connect() 2.2 服务器端server.hpp2.3服务端server.cc2.4客户端client.cc 1.引言 ​ 套接字(Socket)是计算机网络中实现网络通信的一…

【算法】双指针求解盛最多水的容器

Problem: 11. 盛最多水的容器 文章目录 题目解析算法原理讲解复杂度Code 题目解析 首先我们来解析一下本题 题目中说到&#xff0c;要找出其中的两条线&#xff0c;使得它们与 x 轴共同构成的容器可以容纳最多的水。 那我们现在来看最外侧的两根&#xff0c;一个高度为8&#…

GaussDB数据库SQL系列:DROP TRUNCATE DELETE

目录 一、前言 二、GaussDB的 DROP & TRUNCATE & DELETE 简述 1、命令简述 2、命令比对 三、GaussDB的DROP TABLE命令及示例 1、功能描述 2、语法 3、示例 四、GaussDB的TRUNCATE命令及示例 1、功能描述 2、语法 3、示例 4、示例 五、GaussDB的DELETE命令…

一文速学-让神经网络不再神秘,一天速学神经网络基础-激活函数(二)

前言 思索了很久到底要不要出深度学习内容&#xff0c;毕竟在数学建模专栏里边的机器学习内容还有一大半算法没有更新&#xff0c;很多坑都没有填满&#xff0c;而且现在深度学习的文章和学习课程都十分的多&#xff0c;我考虑了很久决定还是得出神经网络系列文章&#xff0c;…

VSCode配置终端默认为cmd命令行方式

1、新建终端 2、点击默认配置文件 3、选择第一个即可&#xff01;

臻图信息基于数字孪生技术搭建智慧电厂管理系统解决方案

随着可再生能源在电力行业中占比不断提升&#xff0c;以及互联网技术的深入和大数据时代的到来&#xff0c;智能化应用正在悄然地改变着电力企业运营模式。臻图信息以数字孪生、ZTMap3D、地理信息为技术手段&#xff0c;从管、查、监、云、端等几个层面全面建设电力监管系统平台…

国产调度器之光——Fsched到底有多能打?

这是一篇推荐我们速石自研调度器——Fsched的文章。 看起来在专门写调度器&#xff0c;但又不完全在写。 往下看&#xff0c;你就懂了。 本篇一共五个章节&#xff1a; 一、介绍一下主角——速石自研调度器Fsched 二、只要有个调度器&#xff0c;就够了吗&#xff1f; 三…

伯俊ERP对接打通金蝶云星空表头表体组合查询接口与应收单新增接口

伯俊ERP对接打通金蝶云星空表头表体组合查询接口与应收单新增接口 对接源平台:伯俊ERP 伯俊科技&#xff0c;依托在企业信息化建设方面的领先技术与实践积累&#xff0c;致力于帮助企业实现全渠道一盘货。伯俊提供数字经营的咨询与系统实施&#xff0c;助力企业信息化升级、加速…

ChatGPT在工业领域的研究与应用探索-数据与工况认知

1. ChatGPT发展现状 ChatGPT是基于OpenAI的GPT-4架构的一种大型语言模型。截至2021年9月&#xff0c;最新版本是GPT-3。在过去的几年里&#xff0c;ChatGPT已经取得了显著的进步&#xff0c;具备更强的自然语言处理和生成能力。 目前&#xff0c;ChatGPT的应用领域广泛&#…

05架构管理之持续集成-DevOps的理解与实现

专栏说明&#xff1a;针对于企业的架构管理岗位&#xff0c;分享架构管理岗位的职责&#xff0c;工作内容&#xff0c;指导架构师如何完成架构管理工作&#xff0c;完成架构师到架构管理者的转变。计划以10篇博客阐述清楚架构管理工作&#xff0c;专栏名称&#xff1a;架构管理…