Codeforces Round #145 (Div. 1) C. Practice

题目链接:

http://codeforces.com/problemset/problem/240/C

C. Practice

input input.txt

output output.txt

Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are n players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 to n. To prepare for the championship, the coach Mr. Floppe decided to spend some number of practices.

Mr. Floppe spent some long nights of his holiday planning how to conduct the practices. He came to a very complex practice system. Each practice consists of one game, all n players of the team take part in the game. The players are sorted into two teams in some way. In this case, the teams may have different numbers of players, but each team must have at least one player.

The coach wants to be sure that after the series of the practice sessions each pair of players had at least one practice, when they played in different teams. As the players' energy is limited, the coach wants to achieve the goal in the least number of practices.

Help him to schedule the practices.

Input

A single input line contains integer n (2 ≤ n ≤ 1000).

Output

In the first line print m — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in m lines.

In the i-th of those lines print fi — the number of players in the first team during the i-th practice (1 ≤ fi < n), and fi numbers from 1 to n— the numbers of players in the first team. The rest of the players will play in the second team during this practice. Separate numbers on a line with spaces. Print the numbers of the players in any order. If there are multiple optimal solutions, print any of them.

Examples

input

Copy

2

output

Copy

1
1 1

input

Copy

3

output

Copy

2
2 1 2
1 1

题目大意:

将编号为1~n的n个人分成两组(每组至少1人),求至少分多少次组,能满足任意取两个人,这两个人必存在被分到过不同的组。

思路:

如果每次调换队伍都是队伍的一半人数对阵另一半人数的话,实际只需要\lceil log_2^n \rceil 

然后每次对半交换前半部分和后半部分就可以

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define EXP exp(1)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
inline int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
int a[1050];
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    int m=ceil(log(n)/log(2));//利用换底公式计算
    int avg=1<<m;
    for(int i=1;i<=n;++i)
        a[i]=i;
    printf("%d\n",m);
    int val=0;
    avg=avg/2;
    int tem=avg;
    for(int i=1;i<=m;++i)
    {
        int xx=0;
        for(int j=1;j<=avg;++j)//计算当前需要输出的队伍的人数
        {
            if(a[j])
                ++xx;
        }
        printf("%d ",xx);
        for(int j=1;j<=avg;++j)//输出队伍组成
        {
            if(a[j])
                printf("%d ",a[j]);
        }
        printf("\n");
        tem/=2;
        int j=1;
        for(int k=1;k<=(1<<val);++k)//交换人员,连续交换tem个后,间隔ten个,继续交换ten个,进行(1<<val)次
        {
            int t;
            for( t=j ; t<j+tem; ++t)
                swap(a[t],a[t+avg]);//需要和后半部分交换
            j=t+tem;
        }
        ++val;
    }
    return 0;
}

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值