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进制保证题目要求,然后按照题目要求输出

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll Pow(ll a,ll b)
{
ll ans=;
ll base=a;
while(b)
{
if(b&)
{
ans*=base;
}
base*=base;
b>>=;
}
return ans;
}
ll n,k,d;
ll solve[][];
int main()
{
int flag=;
cin>>n>>k>>d;
for(int i=;i<=d;i++)
{
if(Pow(k,i)>=n)
{
flag=;
break;
}
}
if(flag)
{
for(int i=;i<=n;i++)
{
ll num=i;
for(int j=;j<=d;j++)
{
solve[i][j]=num%k+;
num/=k;
}
}
for(int i=;i<=d;i++)
{
for(int j=;j<=n;j++)
{
cout<<solve[j][i]<<" ";
}
cout<<endl;
}
}
else
{
cout<<"-1"<<endl;
}
return ;
}

Codeforces Round #261 (Div. 2) C的更多相关文章

  1. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. Codeforces Round #261 (Div. 2) B

    链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...

  3. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  4. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  5. Codeforces Round #261 (Div. 2) - E (459E)

    题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...

  6. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  7. Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)

    题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...

  8. Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

    题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...

  9. Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组

    题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...

  10. Codeforces Round #261 (Div. 2)

    第一场难得DIV2简单+AK人数多: E:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ...

随机推荐

  1. log开启与屏蔽的一种调式方式

    #ifndef _LOGGING_H #define _LOGGING_H #define deg printf #ifdef ENABLE_TRACING #define ENTER() do { ...

  2. Arcgis Engine(ae)接口详解(1):featureClass

    //IFeatureClass 来源请自行解决 IFeatureClass featureClass = null; //获取featureClass的各种名称 //PS:featureClass可以 ...

  3. 常用到的JS 验证(包括例子)

    //验证是否为空    function check_blank(obj, obj_name){         if(obj.value != ''){                  retur ...

  4. 使用libcurl的包装库cpr发起http请求

    cpr GitHub地址https://github.com/whoshuu/cpr 简单示例:cpr_http_request.cpp #include <iostream> #incl ...

  5. js 时间戳精确值的问题

    最近做一个多图上传的功能,通过name + 时间戳命名,结果发现时间戳竟然一样,一直以为是代码逻辑的问题,结果出错在时间戳的获取上了. 关于时间戳的获取方式: 1.Date.parse() var d ...

  6. (C)*p++和*++p区别

    接下来,通过示例彻底理解自增运算符的两种用法(自减的用法与之类似,只不过是加1变成了减1). 1.++i和i++的区别 如清单1(注意代码中的注释): #include <stdio.h> ...

  7. dns服务器报错解决

    搭了个dns服务器,配置完毕老是报错,这里总结一下常见思路: ①关闭firewalld ②关闭selinux ③/var/named里面的配置文件所属用户组是否是root:named ④named.c ...

  8. 【Java】DateUtil(2)

    import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; impor ...

  9. OpenCV——PS滤镜算法之 Ellipsoid (凸出)

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  10. AFNetworking 2.0教程

    在iOS 7中,Apple更新了iOS中的网络基础架构,新推出的网络基础架构是NSURLSession(原来的网络基础架构NSURLConnection). iOS开发中往往会涉及网络数据处理,像其他 ...