Gym 100637F F. The Pool for Lucky Ones
F. The Pool for Lucky Ones
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100637/problem/F
Description
A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has N lanes. Some of the lanes are already occupied by swimmers. Tatar scientists have divided the lanes into the lucky and unlucky ones. The unlucky lanes are those with the maximum amount of swimmers. That is, there is no other lane where there would be more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes are considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to do this they had an agreement with the pool manager saying they can move a single person from any lane to the one neighboring if it was necessary. The swimmer from the first lane can only be moved to the second lane, and the swimmer from the last lane –– to the one before last.
Input
The first line contains an integer N — the amount of lanes in the pool (3 ≤ N ≤ 105). The second line contains N integers pi separated with spaces, describing distribution of swimmers between the lanes where pi is the amount of swimmers on i-th lane (0 ≤ pi ≤ 105).
Output
Output a single number — minimal possible number of unhappy swimmers.
Sample Input
3
1 3 5
Sample Output
5
HINT
题意
泳池,人最多的不快乐,可以将一个人随意移动到相邻泳池,问不快乐的人最少是多少
题解:
我只能说考虑多种情况,暴力就好
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************************************************************
int hash[];
int n;
ll a[];
int main()
{ scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
hash[a[i]]++;
}
ll maxx;
for(int i=; i>=; i--)
if(hash[i])
{
maxx=i;
break;
}
if(maxx==)
{
printf("0\n");
return ;
}
a[]=;
a[n+]=;
if(hash[maxx]!=)
{
ll ans=hash[maxx]*maxx;
for(int i=; i<=n; i++)
{
if(a[i]==maxx)
{
if(a[i+]||a[i-])
{
ans=min(ans,maxx+);
}
if(a[i+]<maxx-&&i+<=n)
{
ans=min((hash[maxx]-)*(maxx),ans);
//return 0;
}
if(a[i-]<maxx-&&i->=)
{
ans=min((hash[maxx]-)*(maxx),ans);
//return 0;
}
}
}
printf("%I64d\n",ans);
}
else
{
for(int i=; i<=n; i++)
{
if(a[i]==maxx)
{
if(a[i+]<maxx-&&i+<=n&&hash[maxx-]==)
{
printf("%I64d\n",maxx-);
return ;
}
if(a[i-]<maxx-&&i->=&&hash[maxx-]==)
{
printf("%I64d\n",maxx-);
return ;
}
}
}
printf("%I64d\n",maxx);
} return ;
}
Gym 100637F F. The Pool for Lucky Ones的更多相关文章
- Gym 100637F F. The Pool for Lucky Ones 暴力
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- CF Gym 100637F The Pool for Lucky Ones
题意:给你一串非负整数,可以将一个非零数减1,加到相邻的数字上,要使其中所有最大数字的和最小. 题解:模拟可以过.也可以分析,可以要减少最大数字和,如果最大数字出现大于等于3次,可以把最大数字加一,或 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Codeforces Gym 100513F F. Ilya Muromets 水题
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
- 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数
http://codeforces.com/gym/102058/problem/F 题意:平面上n个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
- Gym 100952 F. Contestants Ranking
http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...
随机推荐
- IE input file隐藏不能上传文件解决方法
当大神们都在探讨更深层次的问题时,我还在这里转载发些肤浅的问题解决方案.罢了,为了和我一样笨的后来人. 问题: 上传文件时,用<input type="file" /> ...
- commons-logging和Log4j 日志管理/log4j.properties配置详解
commons-logging和Log4j 日志管理 (zz) 什么要用日志(Log)? 这个……就不必说了吧. 为什么不用System.out.println()? 功能太弱:不易于控制.如果暂时不 ...
- Linq实现DataTable的分组统计
DataTable dt = GetTestData(10); //获取10条测试数据 var queryByService = from r in dt.AsEnumerable() group r ...
- linux 的useradd 命令的p选项
linux 的useradd 命令的p选项 错误用法: #useradd gaojian -p gaojian # ...
- explode 和 implode
<?php $str = "HellooooLAAAAAALleeellll33432ll!"; //字符拆分,当2个“l”并列出现,元素结果是空格“ ”,所有的结果是一维数 ...
- 新浪微博XSS攻击源代码下载(2012.06.28_sina_XSS.txt)
function createXHR(){ return window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Mi ...
- iphone数据存储之-- Core Data的使用(一)
http://www.cnblogs.com/xiaodao/archive/2012/10/08/2715477.html 一.概念 1.Core Data 是数据持久化存储的最佳方式 2.数据最终 ...
- search in 2d matrix and serach minimum in rotated array
import java.io.*; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collecti ...
- B,B+,B-,B*树
B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树: 如: B ...
- [BZOJ1786][BZOJ1831]逆序对
[BZOJ1786][BZOJ1831]逆序对 试题描述 输入 输出 输入示例 - - 输出示例 数据规模及约定 见“输入” 题解 首先这题有一个性质,即,填的数从左到右一定不降.证明不妨读者自己yy ...