Codeforces Round #261 (Div. 2) C

Description

Recently Pashmak has been employed in a transportation company. The company has kbuses 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 nintegers. The j-th integer of the i-th line shows which bus the j-th student has to take on thei-th day. You can assume that the buses are numbered from 1 to k.

Examples
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.

题意:有K台公交,n个人,d天,任意两个人全部d天都不能做同一辆公交,输出这种安排

解法:K台公交安排d天,自然是Kd种方法,Ki大于等于n说明符合要求,再将1~n变成k进制保证题目要求,然后按照题目要求输出

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 ll Pow(ll a,ll b)
 5 {
 6     ll ans=1;
 7     ll base=a;
 8     while(b)
 9     {
10         if(b&1)
11         {
12             ans*=base;
13         }
14         base*=base;
15         b>>=1;
16     }
17     return ans;
18 }
19 ll n,k,d;
20 ll solve[2000][2000];
21 int main()
22 {
23     int flag=0;
24     cin>>n>>k>>d;
25     for(int i=1;i<=d;i++)
26     {
27         if(Pow(k,i)>=n)
28         {
29             flag=1;
30             break;
31         }
32     }
33     if(flag)
34     {
35         for(int i=1;i<=n;i++)
36         {
37             ll num=i;
38             for(int j=1;j<=d;j++)
39             {
40                 solve[i][j]=num%k+1;
41                 num/=k;
42             }
43         }
44         for(int i=1;i<=d;i++)
45         {
46             for(int j=1;j<=n;j++)
47             {
48                 cout<<solve[j][i]<<" ";
49             }
50             cout<<endl;
51         }
52     }
53     else
54     {
55         cout<<"-1"<<endl;
56     }
57     return 0;
58 }

 

转载于:https://www.cnblogs.com/yinghualuowu/p/6582028.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值