CodeForces 651B Beautiful Paintings

乱搞题,先对序列排序,每次找到最小的没用过的比前一个大的数字放上去,找不到放没用过的最小的放上去。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <stack>
using namespace std;

const int maxn = 1000 + 10;
int a[maxn];
int ans[maxn];
bool flag[maxn];
int n;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(flag, 0, sizeof flag);
    sort(a + 1, a + 1 + n);
    ans[1] = a[1];
    flag[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        int pos = -1;
        for (int j = 1; j <= n; j++)
        {
            if (flag[j] == 0 && a[j]>ans[i - 1])
            {
                pos = j;
                flag[j] = 1;
                break;
            }
        }
        if (pos != -1)
        {
            ans[i] = a[pos];
        }
        else
        {
            for (int j = 1; j <= n; j++)
            {
                if (flag[j] == 0)
                {
                    pos = j;
                    flag[j] = 1;
                    break;
                }
            }
            ans[i] = a[pos];
        }
    }

    int uu = 0;
    for (int i = 1; i<n; i++) if (ans[i]<ans[i + 1])  uu++;

    printf("%d\n", uu);

    return 0;
}

 

posted @ 2016-03-08 08:37  Fighting_Heart  阅读(252)  评论(0编辑  收藏  举报