• cf B. Two Heaps


    http://codeforces.com/contest/353/problem/B

    题意:要把2*n个两位数分成两部分,使得第一部分上的数和第二部分上的两位数组成四位数。求怎么分能使构成的不同的四位数个数最多

    如果2*n个数都是不同的,怎么分都一样的组成n*n个。如果有相同的,将它们按数量排序,均分到两个集合中就可以。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <map>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int n;
     8 int num[100010];
     9 int a[10010],b[10010];
    10 struct node
    11 {
    12     int x;
    13     int id;
    14     int flag;
    15     int num;
    16     bool operator <(const node &a)const
    17     {
    18         return (num<a.num)||(num==a.num&&x<a.x);
    19     }
    20 }p[100010];
    21 
    22 bool cmp(node a,node b)
    23 {
    24     return a.id<b.id;
    25 }
    26 int main()
    27 {
    28     while(scanf("%d",&n)!=EOF)
    29     {
    30         int cnt=0;
    31         memset(num,0,sizeof(num));
    32         for(int i=1; i<=2*n; i++)
    33         {
    34             int m;
    35             scanf("%d",&m);
    36             p[cnt].id=i;
    37             p[cnt++].x=m;
    38             num[m]++;
    39         }
    40         for(int i=0; i<cnt; i++)
    41         {
    42             p[i].num=num[p[i].x];
    43         }
    44         sort(p,p+cnt);
    45         int t1=0,t2=0;
    46         for(int i=0; i<cnt; i+=2)
    47         {
    48             p[i].flag=1;
    49             if(!a[p[i].x])
    50             {
    51                 a[p[i].x]++;
    52                 t1++;
    53             }
    54             p[i+1].flag=2;
    55             if(!b[p[i+1].x])
    56             {
    57                 b[p[i+1].x]++;
    58                 t2++;
    59             }
    60         }
    61         printf("%d
    ",t1*t2);
    62         sort(p,p+cnt,cmp);
    63         for(int i=0; i<cnt; i++)
    64         {
    65             if(i==0)
    66             {
    67                 if(p[i].flag==1)
    68                 printf("1");
    69                 else
    70                     printf("2");
    71             }
    72             else
    73             {
    74                 if(p[i].flag==1)
    75                     printf(" 1");
    76                 else printf(" 2");
    77             }
    78         }printf("
    ");
    79     }
    80     return 0;
    81 }
    View Code

      

  • 相关阅读:
    CentOS常用的文件操作命令总结
    消息队列技术
    net license tool, EasyLicense !
    Socket、Session、Option和Pipe
    安全配置基线Linux系统
    SolrCloud
    线性表
    微服务系统中的认证策略
    How to use JDBC-Authentication of Spring Boot/Spring Security with Flyway
    使用Akka、Kafka和ElasticSearch等构建分析引擎 -- good
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3930792.html
Copyright © 2020-2023  润新知