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 ...
随机推荐
- 项目中用到的window.showModalDialog(来自网络)
window.showModalDialog相关: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showMo ...
- linux find 命令详解
Linux下 利用find命令删除所有vssver2.scc文件 删除所有vssver2.scc文件 这是我当初查找 Linux find 命令的目的所在 1) find / -name ‘vssv ...
- UESTC 1817 Complete Building the Houses
Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...
- UIView中UIButton设置监听
红色框框是一个uibutton _priceValueLabel是他的父视图, 必须要把button的父视图设置userInteractionEnabled = YES, button的 监听才会生效 ...
- Dmaven.multiModuleProjectDirectory system propery is not set.
eclipse中使用maven插件的时候,运行run as maven build的时候报错-Dmaven.multiModuleProjectDirectory system propery is ...
- MySQL 索引详解大全
什么是索引? 1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引,会保存在额外的文件中. 2. 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结 ...
- 用Python操纵MySQL
本例用Python操纵MySQL,从指定文件读取数据,并对数据进行处理,处理之后批量插入MySQL. 贴上代码: # -*- coding: gbk -*- import re import MySQ ...
- cookie注入的形成,原理,利用总结
一:cookie注入的形成 程序对提交数据获取方式是直接request("c.s.t")的方式.未指明使用request对象的具体方法进行获取. 二:原理 request(&quo ...
- iOS __block类型变量作用域
看下图 在c语言中,2个独立的函数是不可能互相访问局部变量的,但是__block提供了这个功能,它不单单能读变量,还可以对变量进行写!上图说明,block获得了i最后的真实值5,没有只取得0,这都是& ...
- iOS 如何使用自定义字体
首先,你需要有字体文件,比如 xxx.otf,之后你需要到工程的info配置文件中加入Fonts provided by application的值,如下图 之后,就可以使用字体名和UIFont的方法 ...