Codeforces Round #337 (Div. 2) 610B Vika and Squares(脑洞)

AutoSAR系列讲解 - 资料下载 学习资料下载汇总 阅读详情

B. Vika and Squares
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.

Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.

Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has.

The second line of the input contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.

Output

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.

Sample test(s)
input
5
2 4 2 3 3
output
12
input
3
5 5 5
output
15
input
6
10 10 10 1 10 10
output
11
Note

In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.

In the second sample Vika can start to paint using any color.

In the third sample Vika should start painting using color number 5.



题目链接:点击打开链接

给出n种油漆及每种油漆数量, 要求在长方形纸上挨个涂色, 从任意颜色开始涂, 问最多可以涂多少.

找到数量最小的, 求出数量最少的个数, 若数量为n, 则全部可以涂, 若数量为1, 则从下一个开始涂, 其他情况则求出最长的间隔.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
ll n, num, len, tmp, cnt, a[MAXN];
int main(int argc, char const *argv[])
{
	scanf("%lld", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", &a[i]);
	ll mi = INF;
	for(int i = 1; i <= n; ++i)
		mi = min(mi, a[i]);
	for(int i = 1; i <= n; ++i)
		if(a[i] == mi) num++;
	if(num == n) printf("%lld\n", n * a[1]);
	else if(num == 1) printf("%lld\n", n * mi + n - 1);
	else {
		for(int i = 1; i <= n; ++i) {
			if(a[i] == mi) {
				if(tmp > len) len = tmp;
				tmp = 0;
			}
			else tmp++;
		}
		for(int i = 1; i <= n; ++i)
			if(a[i] == mi) break;
			else cnt++;
		len = max(cnt + tmp, len);
		printf("%lld\n", n * mi + len);
	}
	return 0;
}


基于深度学习的工业零件缺陷检测系统 工业零件缺陷检测系统摘要 本文介绍了一个基于深度学习的工业零件缺陷检测系统解决方案。该系统采用Faster R-CNN目标检测算法,结合PyTorch框架和OpenCV图像处理库,实现了对工业零件表面缺陷(如裂纹、划痕、凹坑等)的自动检测与定位。系统包含完整的开发流程:从数据采集与标注、数据增强预处理、模型构建与训练,到最终的评估与部署。相比传统机器视觉方法,该深度学习方案具有更强的特征表示能力和环境适应性,能够有效提升工业质检的准确率和效率。文章详细阐述了系统架构设计、实现细节和优化策略,并提供了完整的代 阅读详情

相关推荐

深入解析Simulink中的条件执行子系统:If Action与Switch Case的实战应用

本文深入解析了Simulink中两种核心的条件执行子系统:If Action Subsystem与Switch Case Action Subsystem。通过实战案例详细阐述了其工作原理、正确搭建方法以及与逻辑控制器(If模块/Switch Case模块)的协同机制,帮助工程师实现清晰、可维护的多分支逻辑控制,并规避常见建模错误。

l3m4n的博客 429

#UPCF Round1 D - Vika and Squares

#UPCF Round1 D - Vika and Squares

mxzf0213的博客 398

SMETANA 安装使用教程

关于SMETANA的安装和简单使用信息

qq_44940977的博客 1168

Codeforces Round #337 (Div. 2) 610D Vika and Segments(线段树)

D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has an infinite sheet of squared

GKHack's Blog 1531

ESP32 Arduino 学习篇(五)TFT_eSPI库

该库有User_Setup.h和 User_Setup_Select.h两个配置文件,支持 ①自定义参数或 ②使用已有配置 驱动TFT屏幕。优点是: 1. 占用空间非常小 2. 动画清晰,充分利用每个像素点 3. 可以非常灵动. 4. 方便进行微调。首先在Libraries里面搜索安装TFT_eSPI库到你的工程文件里面。初始化屏幕, 如果是ST7735,可以往里面传一个参数, 具体用到时再看。缺点是: 1. 容易闪屏 2. 一般不会太复杂 3.需要大量的计算。特别注意: 字库7是仿7段数码屏的样式。

DOF526570的博客 2万+

Excel VBA--按某一列拆分数据到多个文件

首先,将需要拆分的sheet命名为“明细”,接下来运行此代码,按提示操作即可。 在这里插入代码片 Sub chaifen() '定义变量类型 Dim sht, sh1, sh2 As Worksheet Dim k, i, j As Integer Dim irow As Integer Dim col As Integer Dim str As String '程序开始是要求输入按哪一列拆分数...

weixin_43650026的博客 5873

Codeforces Round #337 (Div. 2) B. Vika and Squares (技巧乱搞)

B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has n jars with paints of distinct

滴水穿石,慢慢积累,总会有成果 934

从静态到动态:如何用Deformable 3DGS和4DGS实现高效动态场景建模

本文深入探讨了Deformable 3DGS和4DGS在动态场景建模中的技术突破,详细解析了这两种方法如何高效处理动态内容。Deformable 3DGS通过引入时间维度的变形场扩展传统3DGS,而4DGS则采用四维时空体素分解方法,两者均显著提升了动态场景建模的效率和质量,适用于虚拟现实、增强现实等应用场景。

weixin_29063035的博客 433

Codeforces Round #337 (Div. 2) B. Vika and Squares

B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has n jars with paints of distinct colors....

weixin_30699831的博客 128

【YOLOv11改进 - 特征融合】SDI:多层次特征融合模块,替换contact操作

【YOLOv11改进 - 特征融合】SDI:多层次特征融合模块,替换contact操作

专注于图像领域,主要研究内容包括计算机视觉和深度学习,特别是在图像分类、目标检测和图像生成等方面有深入的研究和实践经验。 1771

Qt C++ 卫星数据接收与处理界面

打开 `MainWindow.ui`,你会发现我们完全是在代码中 (`setupUI`) 创建的 UI。* 访问 [QCustomPlot 官网](https://www.qcustomplot.com/) 下载最新版本的 `qcustomplot.h` 和 `qcustomplot.cpp` 文件。* 对于 FFT,可以使用专门的库如 [FFTW](http://www.fftw.org/),或者 Qt 5.15 及以上版本中提供的 `QFFT` 和 `QComplex` 类。

寒寒豆豆软件公司的博客 148

Codeforces Round #337 (Div. 2)-B. Vika and Squares

原题链接 B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has n jars wit

L. 311

数据挖掘实战-基于决策树算法构建北京市空气质量预测模型

通过分析这些数据,我们将利用决策树算法建立预测模型。决策树算法具有直观易懂、分类效果好等优点,适合用于此类预测问题。我们将采用适当的方法对模型进行训练和优化,以提高预测精度。最终,我们将评估模型的预测效果,并探讨其在实际应用中的可行性和潜在价值。希望通过本实验,能为北京市的空气质量改善工作提供一定的支持。通过基于决策树算法构建的北京市空气质量预测模型的实验研究,我们在多方面取得了显著的进展。首先,我们成功地整合了来自气象、环保、交通等多个领域的大量数据,形成了一个全面而综合的空气质量分析框架。

m0_64336780的博客 2万+

Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心

B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai...

weixin_30438813的博客 123

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Codeforces Round #337 (Div. 2) A Pasha and Stick B Vika and Squares

http://codeforces.com/contest/610/problem/A A题 很简单,就是给出n 然后n分成四段,能组成长方形而不能组成正方形的情况数 #include #include using namespace std; int main() { int n; while(cin >> n) { int ans ;

Pilgrim 623

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1749

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1674

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1665

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1626

Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1616

Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)

C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that t

GKHack's Blog 1599

Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)

C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It is so boring in the summer holiday, isn

GKHack's Blog 1584

Manthan, Codefest 16 633C Spy Syndrome 2(dfs + stl)

C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndro

GKHack's Blog 1574

Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)

A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once upon a time a child got a tes

GKHack's Blog 1504
上一篇: Codeforces Round #336 (Div. 2) 608B Hamming Distance Sum(dp)
下一篇: Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值