P1810 集合分组_NOI导刊2011提高(01)

题目描述

现有K个整数集合,第i个集合有Sumi个元素。

集合中的数都为正数,且不大于N。 现有定义集合A与集合B相似;

1.B与A相似;

2.将A集合删去一个元素,或更改一个元素的值之后A集合与B集合相等。现要将K个集合分成至多M组(M>N),使得每一组内的集合互不相似。要求你给出一种合法的方案。如果无解请输出“impossible”。

输入格式

输入文件第一行有三个数N,K,M,意义如题目所述。

接下来有K行,每行第一数Sum表示序列长度。之后Sum个数为些集合的元素。

输出格式

输出文件有K个数,表示每个集合(按输入顺序)被分到的组的编号(1~M)。

输入输出样例

输入 #1
8 20 12 
5 1 3 5 6 4 
5 1 3 5 6 3 
4 5 6 3 3 
4 5 6 3 4 
4 4 6 5 8 
4 7 7 7 7 
3 7 7 7 
2 2 2 
3 2 2 7 
3 1 2 3 
3 1 2 4 
10 1 2 3 4 5 6 7 8 7 6 
10 8 7 6 5 4 3 2 1 2 1 
20 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 3 5 7 
5 4 6 4 6 4 
5 6 4 6 4 6 
6 6 6 6 6 6 6 
3 6 6 6 
1 1 
1 2
输出 #1
2 
1 
9 
1 
6 
2 
4 
5 
3 
7 
8 
5 
4 
8
7 
9 
1 
1 
2
3

说明/提示

对于30%的数据满足N≤10,M≤2,K≤10。

对于100%的数据满足N≤100,M≤100,K≤50000,Sum≤100。

警告:此题用快读就超时(血淋淋的教训)!

那么,代码?

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
int n,m,k;
int main(){
	cin>>n>>k>>m;
    for(int i=1;i<=k;i++){
        int a,u=0,c;
        cin>>a;
        for(int j=1;j<=a;j++){
			cin>>c;
			u+=c;
		}
		printf("%d\n",u%(n+1)+1);
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/xiongchongwen/p/11845928.html