先上题目+:

C. Pashmak and Buses
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

Input

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

Output

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.

Sample test(s)
input
3 2 2
output
1 1 2 
1 2 1
input
3 2 1
output
-1
Note

Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

  题意:有n个人,k辆车,d个景点,现在要求每个学生每天去一个景点(一共d天)每选一个景点去的时候需要坐某一辆车,现要求这d天里面,没有任意两个人是都坐在同一辆车里面(不能d天都都在一起)。

  做法:一开始我想的是从k辆车里面选d辆,然后将n个学生分配进去,但是这样做好像不行。后来就换了个思路,从k辆车里面选d辆车(可重复)作为某一个学生这d天的乘车方案,然后将这些排列的其中n个求出来就可以了。当然,如果没有这么多的话就输出-1。

上代码:

 #include <bits/stdc++.h>
#define ll long long
#define MAX 1002
using namespace std; ll n,k,d;
ll s[MAX][MAX];
ll arr[MAX],now; bool check(){
ll ans=;
for(ll w=d;w>;w--){
ans=ans*k;
if(ans>=n) return ;
}
return ;
} bool cons(int tot){
if(tot==d){
for(int i=;i<tot;i++){
s[i][now]=arr[i];
}
now++;
if(now==n) return ;
return ;
}
for(int i=;i<=k;i++){
arr[tot]=i;
if(cons(tot+)) return ;
}
return ;
} void print(){
for(int i=;i<d;i++){
for(int j=;j<n;j++){
if(j) cout<<" ";
cout<<s[i][j];
}
cout<<endl;
}
} int main()
{
//freopen("data.txt","r",stdin);
ios::sync_with_stdio(false);
while(cin>>n>>k>>d){
if(check()){
memset(s,,sizeof(s));
now=;
cons();
print();
}else{
cout<<"-1"<<endl;
}
}
return ;
}

/*459C*/

最新文章

  1. js正则表达式的一些研究,截取两个字符串中间的字符串
  2. css 设置圆角
  3. 修改UINavigationController返回按钮颜色
  4. 172. Factorial Trailing Zeroes -- 求n的阶乘末尾有几个0
  5. (hdu)1042 N! 大数相乘
  6. linq中的分组和排序
  7. windows 配置 Scheme + Emacs 编程环境
  8. 关于Wifi室内定位应用中的一些问题:
  9. Redis入门_上
  10. 理解Activity.runOnUiThread()
  11. centos7环境下mysql5.7的安装与配置
  12. JVM初探- 内存分配、GC原理与垃圾收集器
  13. jdk1.8新特性 lambda表达式和Stream
  14. Linux学习man page
  15. pom.xml mevan 的 配置文件
  16. 第一次Scrum会议(10/13)【欢迎来怼】
  17. 路径打印(set以及字符串的相关操作)
  18. Eclipse 插件安装报错问题(已解决)
  19. Linux eject 命令
  20. Ecplise项目转移到Android Studio,以及Genymotion模拟器介绍

热门文章

  1. bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文【区间dp】
  2. 靶形数独 2009年NOIP全国联赛提高组(搜索)
  3. 我要上google
  4. leetcode377 Combination Sum IV
  5. dede手机访问网站跳转到手机端模板
  6. RabbitMQ - Publisher的消息确认机制
  7. poi导出word时设置兼容性
  8. Python的伪造数据库:Faker
  9. Mybatis逆向工程使用方法
  10. dorado 7 使用总结