zoukankan      html  css  js  c++  java
  • Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings

    题目连接:

    http://www.codeforces.com/contest/651/problem/B

    Description

    There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

    We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

    The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

    Output

    Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

    Sample Input

    5
    20 30 10 50 40

    Sample Output

    4

    Hint

    题意

    给你n个数,让你重新安排顺序,使得a[i+1]>a[i]这种情况最多

    题解:

    显然就是每次抽出一个最长子序列,然后这样摆是最优的。

    数据范围只有1000,那我们就暴力抽出最长上升子序列就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1200;
    int vis[maxn];
    int a[maxn];
    vector<int> tmp;
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        int ans = 0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i])continue;
            tmp.push_back(a[i]);
            int now = a[i];
            for(int j=i+1;j<=n;j++)
            {
                if(vis[j])continue;
                if(now>=a[j])continue;
                now=a[j];
                vis[j]=1;
                tmp.push_back(a[j]);
            }
        }
        for(int i=0;i<tmp.size()-1;i++)
            if(tmp[i+1]>tmp[i])ans++;
        cout<<ans<<endl;
    }
  • 相关阅读:
    JMeter学习-图形化 HTML 报表概要说明
    转《Python爬虫学习系列教程》学习笔记
    PYTHON __main__
    python property
    loadrunner脚本,如何获取lr的变量以及lr变量和其他程序语言的变量的转换
    参考链接
    彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义http请求
    如何看Analysis分析图
    Ubuntu16.04安装QQ2015
    Ubuntu16.04运行LSD-SLAM踩坑笔记
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5253123.html
Copyright © 2011-2022 走看看