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的序列,然后要在序列中填1到k的数做d次,使得序列中不存在两个位置在d次中都填一样的数。输出一组方案

然后orz了不知名的神犇才会……看样子好像是类似分治的做法……就是尽量n个位置平均分配1到k,然后变成1 2 3 4 5……k 1 2 3 4 5……k的样子,然后倒着做,变成1 1 1 1 1……2 2 2 2 2…… 3 3 3 3 ……的样子

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int ans[2333][2333]; int main()
{
int i,j,k,m,n,d,delta,l,r;
scanf("%d%d%d",&n,&k,&d);
delta=1;
for(i=1;i<=d;i++)
{
for(j=1;j<=n;j++)
{
ans[i][j]=1;
}
}
for(i=1;i<=d;i++)
{
delta*=k;
if(delta>=n)
{
for(j=2;j<=n;j++)
{
l=i;
while(ans[l][j-1]==k)
{
l--;
}
for(r=1;r<=l;r++)
{
ans[r][j]=ans[r][j-1];
}
ans[l][j]++;
}
for(i=1;i<=d;i++)
{
for(j=1;j<=n;j++)
{
printf("%d ",ans[i][j]);
}
printf("\n");
}
return 0;
}
}
printf("-1\n");
return 0;
}

cf459C Pashmak and Buses的更多相关文章

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

  2. CF459C Pashmak and Buses 打印全排列

    这题假设将终于的结果竖着看,每一列构成的数能够看成是k进制的数.一共同拥有d列,随意两列都不同样,所以这就是一个d位k进制数全排列的问题,一共同拥有k ^ d个排列.假设k ^ d < n,则打 ...

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

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

  4. cf 459c Pashmak and Buses

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

  5. CodeForces - 459C - Pashmak and Buses

    先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...

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

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

  7. codeforce Pashmak and Buses(dfs枚举)

    /* 题意:n个同学,k个车, 取旅游d天! 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 也就 ...

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

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

  9. Codeforces Round #261 (Div. 2)——Pashmak and Buses

    题目链接 题意: n个人,k个车,d天.每一个人每天能够坐随意一个车.输出一种情况保证:不存在两个人,每天都在同一辆车上 (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). 分析: 比赛中 ...

随机推荐

  1. javascript之全局函数

    一.eval() //执行一段字符串中的javascript代码. 语法:eval(code); //可以将javascript写在字符串里面执行. var str = "document. ...

  2. SqlDataReader类

    一.常用属性 名称 说明 Depth 获取一个值,用于指示当前行的嵌套深度.  FieldCount 获取当前行中的列数. HasRows 获取一个值,该值指示 SqlDataReader 是否有行. ...

  3. elasticsearch 搜索不支持单词的部分进行匹配

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-201 ...

  4. centos单用户模式:修改ROOT密码和grub加密

    centos单用户模式:修改ROOT密码和grub加密 CentOSLinux网络应用配置管理应用服务器  Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 ...

  5. 剑指offer-面试题23.从上往下打印二叉树

    题目:从上往下打印出二叉树的每个结点,同一层的结点按照从左到右的顺序打印.例如输入图4.5中 的二叉树,则依次打印出8.6.10.5.7.9.11二叉树结点的定义如下: struct BinaryTr ...

  6. hdu 2896 病毒侵袭_ac自动机

    题意:略 思路:套用ac自动机模板 #include <iostream> #include<cstdio> #include<cstring> using nam ...

  7. tomcat7 https 成功测试

    1,生成证书

  8. 见过的最好的Layout讲解,挺全的

    见过的最好的Layout讲解,挺全的 1. http://wenku.baidu.com/link?url=-9wSWx-oLet8R51iXUbikEMWZF8DK4-n6AqoA5_fk3rtrh ...

  9. Python的if判断与while循环

    1.if判断 Python 编程中 if 语句用于控制程序的执行,基本形式为: if 判断条件: 执行语句 else: 执行语句 Python中使用缩进代替c语言中的大括号,来告诉程序所执行的内容. ...

  10. Android 四大组件之 BroadcastReceiver

    0  简介        BroadcastReceiver也就是“广播接收者”的意思,顾名思义,它就是用来接收来自系统和应用中的 广播.        在Android系统中,广播体现在方方面面,例 ...