Codeforces Round #337 (Div. 2)B
2 seconds
256 megabytes
standard input
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, 3 and 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.
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.
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.
5
2 4 2 3 3
12
3
5 5 5
15
6
10 10 10 1 10 10
11
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种颜色的涂料 1,2,3,,,n
ai代表相应涂料的i有多少升,题目要求 若当前使用涂料x 下一次必须使用涂料x+1 当x==n时 下一次使用涂料1 也就是循环的
问 最多能使用多少涂料
解: 简化一下: 找到涂料最少的容量minx n*minx 为最少使用 其次 便是在一个循环链中寻找最长连续!=minx的子序列的长度
这种是 模仿晏的
#include<bits/stdc++.h>
using namespace std;
#define LL __int64
LL a[200005];
LL max (LL a, LL b)
{
if(a>=b)
return a;
else
return b;
}
int main()
{
LL n,minx;
scanf("%I64d",&n);
scanf("%I64d",&a[1]);
//if(n==1)
// printf("1\n");
// else
minx=a[1];
for(LL i=2; i<=n; i++)
{
scanf("%I64d",&a[i]);
if(minx>a[i])
minx=a[i];
}
LL mm=0,nn=0;
for(LL i=1; i<=n; i++)
{
if(a[i]!=minx)
nn++;
else
{
mm=max(mm,nn);
nn=0;
}
mm=max(mm,nn);
}
//cout<<mm<<endl;
int xx=0;
for(int i=1; i<=n; i++)
{
if(a[i]==minx)
break;
else
xx++;
}
//mm=max(mm,xx);
//xx=0;
for(int i=n; i>=1; i--)
if(a[i]==minx)
break;
else
xx++;
mm=max(mm,xx);
// cout<<mm<<endl;
printf("%I64d\n",minx*n+mm);
return 0;
}
然后机智一下 想起之前的回文操作 加一倍变成a[2*n] 呵呵
#include<bits/stdc++.h>
using namespace std;
#define LL __int64
LL a[400005];
LL max (LL a, LL b)
{
if(a>=b)
return a;
else
return b;
}
int main()
{
LL n,minx;
scanf("%I64d",&n);
scanf("%I64d",&a[1]);
//if(n==1)
// printf("1\n");
// else
minx=a[1];
a[n+1]=a[1];
for(LL i=2; i<=n; i++)
{
scanf("%I64d",&a[i]);
a[n+i]=a[i];
if(minx>a[i])
minx=a[i];
}
LL mm=0,nn=0;
for(LL i=1; i<=2*n; i++)
{
if(a[i]!=minx)
nn++;
else
nn=0;
mm=max(mm,nn);
}
// cout<<mm<<endl;
printf("%I64d\n",minx*n+mm);
return 0;
}
Codeforces Round #337 (Div. 2)B的更多相关文章
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造
C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...
- 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 jar ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis
题目链接:http://codeforces.com/contest/610/problem/C 解题思路: 将后一个矩阵拆分为四个前一状态矩阵,其中三个与前一状态相同,剩下一个直接取反就行.还有很多 ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- Codeforces Round #337 (Div. 2)
水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 数学
C. Harmony Analysis The semester is already ending, so Danil made an effort and decided to visit a ...
- Codeforces Round #337 (Div. 2) B. Vika and Squares 水题
B. Vika and Squares Vika has n jars with paints of distinct colors. All the jars are numbered from ...
随机推荐
- Java注解的基本原理
注解的本质就是一个继承了Annotation接口的接口,一个注解准确意义上来说,只不过是一种特殊注释而已,如果没有解析他的代码,他可能连注释都不如. 解析一个类或者方法的注解往往有两种形式,一种是编译 ...
- 换抵挡装置 (Kickdown,ACM/ICPC NEERC 2006,UVa1588
题目描述:算法竞赛入门经典习题3-11 题目思路:1.两长条移动匹配 2.上下调换,取小者 #include <stdio.h> #include <string.h> int ...
- java核心技术 笔记
一 . 总览 1. 类加载机制:jdk内嵌的class_loader有哪些,类加载过程.--后面需要补充 2. 垃圾收集基本原理,常见的垃圾收集器,各自适用的场景.--后面需要补充 3. 运行时动态编 ...
- C语言struct中的长度可变数组(Flexible array member)
C_struct中的长度可变数组(Flexible array member) Flexible array member is a feature introduced in the C99 sta ...
- Python3 深浅拷贝
一 定义 在Python中对象的赋值其实就是对象的引用.当创建一个对象,把它赋值给另一个变量的时候,python并没有拷贝这个对象,只是拷贝了这个对象的引用而已. 浅拷贝: 浅拷贝值只拷贝一层,具有自 ...
- HDU 3268/POJ 3835 Columbus’s bargain(最短路径+暴力枚举)(2009 Asia Ningbo Regional)
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...
- vue.js学习之 打包为生产环境后,页面为白色
vue.js学习之 打包为生产环境后,页面为白色 一:配置问题 当我们将项目打包为生产环境后,在dist文件夹下打开index.html,会发现页面为白色. 1:打开config>index.j ...
- 给你的WP应用加上帮助文档
背景 这算是Windows Phone编程回顾续篇, 接着给大家聊WP开发经验. 在开发了数个WP应用并发布后, 陆续收到很多反馈邮件, 其中接近一半的邮件是在问"某某功能有没有?" ...
- 原生javascript自定义input[type=radio]效果
2018年6月27日 更新 找到最为简单的仅仅使用css3的方案 <!DOCTYPE html> <html lang="en"> <head> ...
- SonarQube安装
要求 至少1G以上内存,推荐为2G Java:Oracle JRE 7u75+,OpenJDK 7u75+ 数据库: Microsoft SQL Server 2008/2012/2014 MySQL ...