Thứ Hai, 26 tháng 11, 2012

Problem Beauty Pageant

Link: http://codeforces.com/problemset/problem/246/C

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 kdays. 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 airepresents 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 nk (1 ≤ n ≤ 501 ≤ k ≤  ) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integersa1, 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 


Thuật toán:

Code:

/*
    Coder : Nguyen Duc Tam
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<utility>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>

using namespace std;

#define REP(i, start, end, step) for(int i = start; i < end; i += step)
#define DOWN(i, start, end, step) for(int i = start; i > end; i -= step)
#define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
#define X first
#define Y second

#define L(x,i) ((x) << (i))
#define R(x,i) ((x) >> (i))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define NOT(a) (~(a))
#define SB(x,i) (OR((x), L(1, (i))))    // x | 1 << i 
#define CB(x,i) (AND((x),NOT(L(1,(i))))) // x & ~(1 << i)
#define TB(x,i) (AND((x), L(1,(i))))    // x & (1 << i) 

#define FILL(a,val) memset(a,val,sizeof(a));
#define INIT(a,l,r,val) REP(i,l,r,1) (a)[i] = val;
#define DIG(c) (int)((c) - '0')
#define CHR(c) (char)((c) + '0')
#define LOW(c) (char)((c) + 32)
#define UPP(c) (char)((c) - 32)

#define EPS 1e-7
#define OO 1000000005
#define N 100005

const int DAY[13] = {-1,31,29,31,30,31,30,31,31,30,31,30,31};


typedef pair<int,int> II;
typedef pair<II,int> D;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned char UC; 

int n,k,a[51];
map<int,vector<int> > ma;
set<int> s;

int main()
{
    #define Off  false
    if(Off)
    {
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    }
    cin >> n >> k;
    REP(i,0,n,1) cin >> a[i];
    sort(a,a + n);
    
    for(int i=0; i < n && k; i++)
    {
        for(int j = n - i - 1; j > -1 && k; j--)
        {
            printf("%d ",i + 1);
            for(int t = n - 1; t >= n - i; t--) printf("%d ",a[t]);
            printf("%d\n",a[j]);
            k--;    
        }   
    }
    return 0;
}


Không có nhận xét nào:

Đăng nhận xét