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 ...
随机推荐
- 【20180807模拟测试】t1 function
low逼的我也只能写这样的水题... 题面 对于一个整数,定义 f(x)为他的每个数位的阶乘的乘积.例如 f(135)=1! * 3! * 5! =720.给出一个数 a(可以包含前缀零),a 满足他 ...
- 【转载】appium 操作汇总
'''.appium api第二弹 锋利的python,这是初稿,2015/1/5 如有错误的地方,请同学们进行留言,我会及时予以修改,尽量整合一份ok的api 作者:Mads Spiral QQ:7 ...
- Solidity中的基本类型转换
Solidity中的基本类型转换(十四)|入门系列 2017/4/29 posted in Solidity入门系列 点击查看原文,获得优化的排版. 隐式转换 如果一个运算符能支持不同类型.编译器会隐 ...
- nordic mesh中的消息缓存实现
nordic mesh中的消息缓存实现 代码文件msg_cache.h.msg_cache.c. 接口定义 头文件中定义了四个接口,供mesh协议栈调用,四个接口如下所示,接口的实现代码在msg_ca ...
- Python3 Tkinter-Entry
1.创建 from tkinter import * root=Tk() t1=Entry(root) t1.pack() root.mainloop() 2.绑定变量 from tkinter im ...
- 解决python中文编码错误问题
对于初学者而言,编码问题或许还没有没重视起来,但是编码问题是中文开发者必须面对的.今天来看下python开发中如何解决编码问题.注意:本篇讲的是最常见的一种编码问题,其他编码问题,如json函数引起的 ...
- 寒假作业end
开始写博客的个人体会 自己打的链表过不了,果然,心存侥幸是不行的,被揪出来也不错,很感谢畅畅酱. 学术诚信的重要性 爱因斯坦说过:"大多数人说是才智造就了伟大的科学家,他们错了,是人格.&q ...
- Java中Collection和Collections的区别(转载)
转载来源:http://www.cnblogs.com/dashi/p/3597937.html 1.java.util.Collection 是一个集合接口(集合类的一个顶级接口).它提供了对集合对 ...
- iOS开发NS_ENUM和NS_OPTIONS区别
OC里枚举的两种类型.NS_ENUM和NS_OPTIONS本质上是一样的都是枚举. typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UI ...
- Vue自定义事件,$on(eventName) 监听事件,$emit(eventName) 触发事件
<!--自定义事件 使用 $on(eventName) 监听事件 使用 $emit(eventName) 触发事件--> <div id="app15"> ...