先上题目+:

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*/

CodeForces - 459C - Pashmak and Buses的更多相关文章

  1. codeforces 459C Pashmak and Buses 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...

  2. codeforces 459C Pashmak and Buses(模拟,组合数A)

    题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...

  3. CodeForces 459C Pashmak and Buses(构造)题解

    题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...

  4. Codeforces 459C Pashmak and Buses 机智数学题

    这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...

  5. cf 459c Pashmak and Buses

    E - Pashmak and Buses Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  6. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  7. CF459C Pashmak and Buses (构造d位k进制数

    C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...

  8. cf459C Pashmak and Buses

    C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

随机推荐

  1. HTML <input>标签属性

  2. 服务器出现 nginx 502 Bad Gateway

    发生原因1.PHP FastCGI进程数不够用 当网站并发访问巨大时,php fastcgi的进程数不有一定的保障,因为cgi是单线程多进程工作的,也就是说cgi需要处理完一个页面后再继续下一个页面. ...

  3. redis的两种备份方式

    Redis提供了两种持久化选项,分别是RDB和AOF. 默认情况下60秒刷新到disk一次[save 60 10000 当有1w条keys数据被改变时],Redis的数据集保存在叫dump.rdb一个 ...

  4. [转]c++中的string常用函数用法总结

    标准c++中string类函数介绍 注意不是CString之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作为 ...

  5. 最大流增广路(KM算法) HDOJ 1533 Going Home

    题目传送门 /* 最小费用流:KM算法是求最大流,只要w = -w就可以了,很经典的方法 */ #include <cstdio> #include <cmath> #incl ...

  6. 309 Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

    Say you have an array for which the ith element is the price of a given stock on day i.Design an alg ...

  7. linux创建ftp用户以及指定目录问题

    linux创建ftp用户以及指定目录问题 创建用户命令:如我的目录是根目录下的 MyWeb 用户名:xdh2571 #useradd -G ftp -d /MyWeb -M xdh2571#passw ...

  8. ionic3带参数返回原来页面

    最近用ionic3+angular4做项目.我遇到了个问题,我返回原来页面时一般都会调用this.navCtrl.pop()方法,但这个方法不能携带参数.怎么办? 可以写个回调方法. 我在a页面定义个 ...

  9. EF CodeFirst 不得不说的Where与OrderBy

    先来聊上5毛钱的“排序” Code: using (ApplicationDbContext Db=new ApplicationDbContext()) { var res = Db.Threes. ...

  10. Angular——$http

    基本介绍 $http用于向服务端发起异步请求,同时还支持多种快捷方式如$http.get().$http.post().$http.jsonp.$hhtp也是属于内置服务的一种,这里特意提出来写一篇用 ...