• CF 253B Two Heaps


    #include<stdio.h>
    #include<algorithm>
    #include<map>
    using namespace std;
    struct Node
    {
        int x;
        int number;
        int i;
        int flag;
    }a[300];
    int b[300];
    map<int,int>ma,mb1,mb2;
    bool cmp1(Node a,Node b)
    {
        if(a.i<b.i)return true;
        return false;
    }
    bool cmp2(Node a,Node b)
    {
        if(a.number<b.number)return true;
        if(a.number==b.number&&a.x<b.x)return true;
        return false;
    }
    int main()
    {
        int i,n;
        while(scanf("%d",&n)!=EOF)
        {
            ma.clear();
            mb1.clear();
            mb2.clear();
            n=2*n;
            for(i=0;i<n;i++)
            {
                scanf("%d",&a[i].x);
                a[i].i=i;
                ma[a[i].x]++;
                //a[i].number=1;
            }
            for(i=0;i<n;i++)
                a[i].number=ma[a[i].x];
            sort(a,a+n,cmp2);//number
            /*for(i=0;i<n;i++)
                printf("%d:%d ",a[i].x,a[i].number);*/
            for(i=0;i<n;i+=2)
            {
                a[i].flag=1;
                mb1[a[i].x];
                a[i+1].flag=2;
                mb2[a[i+1].x];
            }
            sort(a,a+n,cmp1);
            printf("%d
    ",mb1.size()*mb2.size());
            for(i=0;i<n-1;i++)
            printf("%d ",a[i].flag);
            printf("%d
    ",a[n-1].flag);
        }
        return 0;
    }
  • 相关阅读:
    _proto_和prototype的区别
    ajax
    图片预加载
    loading动画
    WinSCP
    检测竖屏 横屏
    webstrom hbuilder快捷键
    vue 引入sass
    npm install -save 和 -save-dev 区别
    打乱数组顺序
  • 原文地址:https://www.cnblogs.com/XDJjy/p/3365403.html
Copyright © 2020-2023  润新知