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 ...
随机推荐
- UniMelb Comp30022 IT Project (Capstone) - 1.Android入门
1. Android入门 Android系统架构 Android系统:四层架构.五块区域 1. Linux内核层 Linux Kernel:为Android设备的硬件提供了底层驱动 2. 系统运行库层 ...
- bug 调试
系统性能分析中,CPU.内存和 IO 是主要关注项.----系统层面 1. 对于 CPU,如果是常见的 Linux,可以先用 top 命令查看负载状况. top -H -p [pid] pstree ...
- C中文件操作的文本模式和二进制模式,到底有啥区别?
在C中,使用fopen打开文件有两种模式:一种是文本模式,一种是二进制模式.那这两种模式之间有什么区别,是不是使用文本模式打开的文件就只能使用文本函数比如fprintf来操作,而使用二进制打开的文件就 ...
- 《剑指Offer》题四十一~题五十
四十一.数据流中的中位数 题目:如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中 ...
- 《剑指Offer》题二十一~题三十
二十一.调整数组顺序使奇数位于偶数前面 题目:输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 测试用例: 功能测试:输入数组中的奇 ...
- Thunder团队第一周 - Scrum会议5
本节内容: 工作照片 会议时间 会议地点 会议内容 Todo list 燃尽图 Scrum会议5 小组名称:Thunder 项目名称:爱阅app Scrum Master:邹双黛 工作照片: 参会成员 ...
- 软件工程课堂作业(二)续——升级完整版随机产生四则运算题目(C++)
一.设计思想: 1.根据题目新设要求,我将它们分为两类:一类是用户输入数目,根据这个数目改变一系列后续问题:另一类是用户输入0或1,分情况解决问题. 2.针对这两类要求,具体设计思路已在上篇博文中写出 ...
- ubuntu apache nginx 启动 关闭
转载自:http://www.comflag.com/2011/05/01/apache-web.htm 电影<社交网络>中,facebook创始人马克.扎克失恋后入侵哈佛大学宿舍楼服务器 ...
- MFC动态创建控件及其消息响应函数
这几天专门调研了一下MFC中如何动态创建控件及其消息响应函数. 参考帖子如下: (1)http://topic.csdn.net/u/20101204/13/5f1b1e70-2f1c-4205-ba ...
- HTML页面垂直滚动条不见
<body style="overflow-y:scroll;"> </body>