0
点赞
收藏
分享

微信扫一扫

CodeForces - 240 C. Practice 模拟或者二分或者规律


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


2


Output


1 1 1


Input


3


Output


2 2 1 2 1 1


题意:

给编号为1~n的人,每一训练可以将其分为两队,队与队之间可以相会打仗,问要求每两个人之间都得打一次的最少的训练数?

分析:

以8为例:

3次即可

1234   5678

1256   3478

1458   3276

 

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long ll ;
const int N=200000+7;
int a[N];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
int ans=ceil(log(n)/log(2));
for(int i=1; i<=n; ++i)
{
a[i]=i;
}
printf("%d\n",ans);
int len=(1<<ans)/2;
int mid=(1<<ans)/2;
for(int i=1;i<=ans;i++)
{
int cnt=0;
for(int j=1;j<=mid;j++)
{
if(a[j]!=0)
cnt++;
}
printf("%d ",cnt);
for(int j=1;j<=mid;j++)
{
if(a[j]!=0)
printf("%d ",a[j]);
}
cout<<endl;

len/=2;
int num=0;
for(int j=1;j<=mid;j+=len)
{
num++;
for(int t=j;t<j+len;t++)
{
swap(a[t],a[t+mid]);
}
j+=len;
if(num>=(1<<(i-1)))
break;

}


}


return 0 ;
}

 

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long ll ;
const int N=200000+7;
int a[N];
vector<int> mapp[N];
void two_solve(int deep,int l,int r)
{
if(l==r) return;
int mid=(l+r)>>1;
for(int i=l;i<=mid;i++)
{
mapp[deep].push_back(a[i]);
}

two_solve(deep+1,l,mid);
two_solve(deep+1,mid+1,r);

}
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
int ans=ceil(log(n)/log(2));
for(int i=1; i<=n; ++i)
{
a[i]=i;
}
printf("%d\n",ans);

two_solve(1,1,n);
for(int i=1;i<=ans;i++)
{
printf("%d ",mapp[i].size());
for(auto x:mapp[i])
printf("%d ",x);
cout<<endl;
}
return 0 ;
}

 

 

 

举报

相关推荐

0 条评论