zoukankan      html  css  js  c++  java
  • CF 151 C. Beauty Pageant

    C. Beauty Pageant
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.

    All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.

    On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.

    Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.

    Input

    The first line contains two integers n, k (1 ≤ n ≤ 50; 1 ≤ k ≤  ) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the beauties of the battalion soldiers.

    It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.

    Output

    Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 ≤ ci ≤ n) — the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i — the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.

    Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.

    Sample test(s)
    Input
    3 3
    1 2 3
    Output
    1 1
    1 2
    2 3 2
    Input
    2 1
    7 12
    Output
    1 12 

    n个元素两两互不相同。。
    我们只要把元素排好序就好做了。
    比如五个元素a[1],a[2],a[3],a[4],a[5].排好从大到小的顺序。
    1  a[1],a[2],a[3],a[4],a[5]
    2  a[1]+a[2],a[1]+a[3],a[1]+a[4],a[1]+a[5]
    3  a[1]+a[2]+a[3]  a[1]+a[2]+a[4]  a[1]+a[2]+a[5]
    4  a[1]+a[2]+a[3]+a[4]  a[1]+a[2]+a[3]+a[5]
    5 a[1]+a[2]+a[3]+a[4]+a[5]
     
    这里正好n*(n+1)/2个元素,且他们的和肯定不会相等。。所以。。。就很简单了。
    View Code
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 int cmp(const void*x,const void*y)
     4 {
     5     return *(int*)y-*(int*)x;
     6 }
     7 int main()
     8 {
     9     int n,k,count;
    10     int a[60];
    11     while(~scanf("%d%d",&n,&k))
    12     {
    13         count=0;
    14         int flag=0;
    15         for(int i=0;i<n;i++)
    16         {
    17             scanf("%d",&a[i]);
    18         }
    19         qsort(a,n,sizeof(a[0]),cmp);
    20         if(k<=n)
    21         {
    22             for(int i=0;i<k;i++)
    23             printf("1 %d\n",a[i]);
    24         }
    25         else
    26         {
    27             for(int i=0;i<n;i++)
    28             printf("1 %d\n",a[i]);
    29             count=n;
    30             for(int r=2;r<=n;r++)
    31             {
    32                 
    33                 for(int j=r-1;j<n;j++)
    34                 {
    35                     printf("%d",r);
    36                     for(int i=0;i<r-1;i++)
    37                    printf(" %d",a[i]);
    38                    printf(" %d\n",a[j]);
    39                    count++;
    40                    if(count>=k)
    41                    {
    42                        flag=1;
    43                        break;
    44                    }
    45                    
    46                 }
    47                 if(flag) break;
    48             }
    49         }
    50     }
    51 }
     
     
  • 相关阅读:
    查看centos版本
    Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException 拒绝访问 / 出现了内部错误 c# – 当使用X509Certificate2加载p12/pfx文件时出现
    asp.net asp.net application 升级到 asp.net web 解决找不到控件 批量生成.designer文件
    netcore发布到 iis 设置 部署 环境 变量
    sqlserver 3145
    windows server 2012 远程桌面不好使
    VirtualBox 桥接模式,虚拟机ping不通宿主机
    移动端笔记
    css笔记——关于css中写上charset “utf-8”
    工作笔记——前端分页数据回显
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2788771.html
Copyright © 2011-2022 走看看