zoukankan      html  css  js  c++  java
  • 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 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;
    }
  • 相关阅读:
    HTML5开发 桌面提醒功能
    自然框架总体设计
    Inversion of Logging
    Wind.js在移动跨平台框架PhoneGap中的异步体验
    MSBuild基本概念
    PortalBasic Web 应用开发框架:应用篇
    检测常见ASP.NET配置安全漏洞
    线程与进程的比较
    多层架构下的一个进销存项目
    Model Driven Architecture
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4674295.html
Copyright © 2011-2022 走看看