codeforces 234G Practice

G. 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
1
1 1
input
3
output
2
2 1 2
1 1

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

模拟:

#include<cstdio>
const int N=1002;
int a[12][N],cnt[12];
void dfs(int l,int r,int d)
{
	int i,m=(l+r)>>1;
	for(i=l;i<=m;i++)a[d][cnt[d]++]=i;
	if(l<r)
	{
		dfs(l,m,d+1);
		dfs(m+1,r,d+1);
	}
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n,i,j,ans;
	while(~scanf("%d",&n))
	{
		for(ans=1;1<<ans<n;ans++);
		for(i=1;i<=ans;i++)cnt[i]=0;
		printf("%d\n",ans);
		dfs(1,n,1);
		for(i=1;i<=ans;i++)
		{
			printf("%d",cnt[i]);
			for(j=0;j<cnt[i];j++)printf(" %d",a[i][j]);
			puts("");
		}
	}
	return 0;
}

位运算:

#include<cstdio>
int main()
{
        freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n,i,j,ans,cnt;
	while(~scanf("%d",&n))
	{
		for(ans=1;1<<ans<n;ans++);
		printf("%d\n",ans);
		for(i=0;i<ans;i++)
		{
			cnt=0;
			for(j=0;j<n;j++)if(1<<i&j)cnt++;
			printf("%d",cnt);
			for(j=0;j<n;j++)if(1<<i&j)printf(" %d",j+1);
			puts("");
		}
	}
	return 0;
}


c++14 ## 题目描述 小 L 给你出了一道简单数学题。 对于一个长度为 $n$ 的排列 $p_n$,我们在 $i$ 与 $p_i$ 之间连无向边,设形成的连通块个数为 $C(p_n)$。 对于一个连通块 $S$,如果他包含的点的编号为 $x_1,x_2\dots x_k$,那么他的权值为 $w(S)=\sum\limits_{i=1}^k 2^{x_i}$。 如果连通块分别为 $S_1,S_2\dots S_{C(p_n)},那么$记该排列的权值为 $\sum\limits_{i=1}^{C(p_n)}2^{w(S_i)}$。 记 $F(n,m)$ 表示 $C(p_n)=m$ 的 $p_n$ 个数。 记 $G(n,m)$ 为 $C(p_n)=m$ 的 $p_n$ 的不同权值数量。 这里认为 $F(0,0)=G(0,0)=1$。 现在有 $Q$ 次询问,每次给出 $op,n,m$: - 如果 $op=1$,你需要输出 $F(n,m)\bmod 2$。 - 如果 $op=2$,你需要输出 $G(n,m)\bmod 2$。 ## 输入格式 第一行一个整数 $Q$ 代表询问次数。 接下来 $Q$ 行,每行三个整数 $op,n,m$ 代表小 L 的一次询问。 - 如果 $op=1$,你需要输出 $F(n,m)\bmod 2$。 - 如果 $op=2$,你需要输出 $G(n,m)\bmod 2$。 ## 输出格式 一行一个长度为 $Q$ 的 $01$ 字符串代表答案序列。 ## 输入输出样例 #1 ### 输入 #1 ``` 20 1 3 8 2 10 2 2 8 2 1 3 1 2 3 3 1 1 5 1 5 10 2 9 8 1 9 5 2 6 6 2 1 0 2 6 4 1 5 3 1 2 5 2 4 7 2 0 2 2 0 5 2 8 1 2 7 1 1 8 8 ``` ### 输出 #1 ``` 01101000110110000111 ``` ## 说明/提示 - 对于 $20\%$ 的数据,$0\leq n,m\leq 10$。 - 对于 $40\%$ 的数据,$0\leq n,m\leq 5000$。 - 对于另外 $15\%$ 的数据,$op=1$。 - 对于另外 $15\%$ 的数据,$op=2$。 - 对于另外 $15\%$ 的数据,$0\leq n,m\leq 10^5$。 - 对于 $100\%$ 的数据,$1\leq Q\leq 10^6,0\leq n,m\leq 10^9,1\leq op\leq 2$。
最新发布
12-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值