Gym 100637F F. The Pool for Lucky Ones 暴力
2015-07-24 18:44
330 查看
F. The Pool for Lucky Ones
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/gym/100637/problem/FDescription
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.[b]Input[/b]
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).
[b]Output[/b]
Output a single number — minimal possible number of unhappy swimmers.
[b]Sample Input[/b]
3
1 3 5
[b]Sample Output[/b]
5
HINT
[b]题意[/b]
游泳池,拥有人数最多的水道是不快乐的
你可以移动一个人到相邻的水道,问你最少不快乐的人数是多少
[b]题解:[/b]
暴力枚举就好了,暴力往左移再往右移,然后再扫一遍
[b]代码[/b]
#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 long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) const int maxn=202501; #define mod 1000000007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** ll d[maxn]; ll a[maxn]; int main() { int n=read(); ll maxn=0; for(int i=1;i<=n;i++) { a[i]=read(); d[a[i]]++; maxn=max(maxn,a[i]); } ll ans=d[maxn]*maxn; for(int i=1;i<=n;i++) { if(a[i]==0) continue; if(i!=n) { d[a[i]]--; d[a[i]-1]++; d[a[i+1]+1]++; d[a[i+1]]--; for(int j=maxn+100;j>0;j--) { if(d[j]>0) { ans=min(d[j]*j,ans); break; } } d[a[i]]++; d[a[i]-1]--; d[a[i+1]+1]--; d[a[i+1]]++; } if(i!=1) { d[a[i]]--; d[a[i]-1]++; d[a[i-1]+1]++; d[a[i-1]]--; for(int j=maxn+100;j>0;j--) { if(d[j]>0) { ans=min(d[j]*j,ans); break; } } d[a[i]]++; d[a[i]-1]--; d[a[i-1]+1]--; d[a[i-1]]++; } } cout<<ans<<endl; }
相关文章推荐
- WPF 逻辑树和可视化树
- Swiper滑动Html5手机浏览器自适应
- 网络编程基础知识学习要点记录
- Android 获取view在屏幕中的位置
- JVM垃圾分代回收算法详解
- 算法(第四版)学习笔记之java实现归并排序
- FL2440裸机开发之LED
- android getViewTreeObserver的使用
- Tomcat本地服务器搭建
- sql 语句在数据库取数据(包括图片)
- Vert.x-Web的讲解和使用(二)
- 单调队列--优化dp
- 关于欧拉函数的递推方法的证明
- 黑马程序员——Java基础---GUI
- 日子前的天数
- 微信公众平台DIY文章排版格式
- failed to open stream: HTTP wrapper does not support writeable connections
- Java内存区域与模拟内存区域异常
- 解释器与编译器
- 观察者模式-Observer Pattern