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 ...
随机推荐
- lintcode 二分查找
题目:二分查找 描述:给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. c ...
- CodeForces 838B Diverging Directions 兼【20180808模拟测试】t3
描述 给你一个图,一共有 N 个点,2*N-2 条有向边. 边目录按两部分给出 1. 开始的 n-1 条边描述了一颗以 1 号点为根的生成树,即每个点都可以由 1 号点到达. 2. 接下来的 N-1 ...
- python同时遍历两个list
两个list, 有对应关系,希望同时完成遍历 用迭代器迭代的方法也不是不可以,python提供了更直观的方法: 可以使用zip把两个list打包 , 类似: list1 = [1,2,3,4] lis ...
- 4-2:实现cp命令
#include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h& ...
- coding.net 版本控制
这是版本测试的所有内容,其中用到了 git 和coding的远程连接. 代码及版本控制 git地址:https://git.coding.net/tianjiping/11111.git
- Scala快速入门-基础
HelloWorld 从HelloWorld开始,使用scala IDE编辑器. 新建scala project 新建scala object 编写HelloWorld run as scala ap ...
- 在 Range 对象中,Min (14)必须小于或等于 max (-1)。
DataTable dt = ds.Tables[]; DataRow[] drs = dt.Select("Id=" + categoryID ); 解决方法:将参数用单引号阔起 ...
- 再看RCU
从昨天晚上开始,我就立志要把RCU拿下,昨晚加今天早上看了RCU的东西,太细节的原理我就不扣了,放弃,知道RCU是怎么用的就可以了,赶紧看文件系统中dcache的管理了. 说说RCU,RCU其实是很简 ...
- CDN概念基本介绍
CDN概念基本介绍 一 . CDN简介 什么是CDN? CDN的全称是Content Delivery Network,即内容分发网络. 其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的 ...
- nginx 反向代理 ,入门
入门:http://www.cnblogs.com/jjzd/p/6691500.html 启动,重新加载:http://blog.csdn.net/zhongguozhichuang/article ...