Codeforce 240C Practice

来源:互联网 发布:linux系统支持的游戏 编辑:程序博客网 时间:2024/05/01 09:26
C. Practice
time limit per test
1 second
memory limit per test
256 megabytes
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 inm 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.

Sample test(s)
input
2
output
11 1
input
3
output
22 1 21 1
/***                      二分+搜索      题目大意:      有n个人,要进行分组比赛,每次比赛,第一组的任何人和另外一组的任何一人都算是进行了一场比赛,      要求是:      每一轮比赛会将n个人分成两组 , 每组人数可以不同;      若干轮结束后 , 每个人和其他的n-1人至少打过1场;      比赛轮回最少.            输入:人数n      输出:比赛最少的轮数,输出每一轮其中一支队伍中的队员编号.            思路:      我们假设(a,b)二元组表示a和b的一场比赛,      在分组的时候 , 进行二分 :      为了使每一轮比赛能够产生尽可能多的(a,b)组合,每队的人数要尽可能平均,      因此,每次能够将人数均分至两队,便可能使得轮回最少,所以        第一轮分组,每组有n/2个人,        第一轮以后的分组,也尽量保持平分;                在第一轮结束后 , 我们发现同一队的队员没有进行比赛 , 所以 ,        我们将一队的人进行分组 , 然后 , 我们发现 , 对一队的队员进行分组比赛的问题,        与原问题相同 , 只是问题的规模缩小了 , 典型的分治思想 .                但是,将第一轮的两队再次分组后,会出现四支队伍,而题目要求每一轮只能有两支队伍,        因此,我们需要将四支队伍进行交叉合并 !         第一支队伍的第一组与第二支队伍的第一组进行组合,与两支支队伍的第二组组合进行比赛,        这样,同一队的两组便进行了比赛,虽然会产生多余的(a,b)二元组,但对问题并无影响;                然后,进行第三轮,第三轮实际上是对第一支队伍的两组和第二支队伍的两组进行分组,        总共会形成八支队伍,八支队伍再进行组合即可......                直至,每支队伍只有自己一个人;***/#include <iostream>#include <cstring>#include <cstdio>using namespace std;int maps[1000][10000];int n;int mx;void init(int step,int l,int r){    if(l==r) return;//结束条件    if(step>mx)//更新轮数        mx=step;    int mid=(l+r)/2;//二分    for(int i=l;i<=mid;i++)        maps[step][i]=1;//队伍组合    init(step+1,l,mid);//对第一队进行分组    init(step+1,mid+1,r);//对第二队进行分组}int main(){    freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);    memset(maps,0,sizeof(maps));    cin>>n;    mx=0;    init(1,1,n);    cout<<mx<<endl;//轮数唯一    for(int i=1;i<=mx;i++)//结果不唯一    {        int cnt=0;        for(int j=1;j<=n;j++)        {            if(maps[i][j]) cnt++;        }        cout<<cnt;        for(int j=1;j<=n;j++)            if(maps[i][j]) cout<<" "<<j;        cout<<endl;    }    return 0;}