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. Delphi泛型评测(30篇)

    http://www.cnblogs.com/jxgxy/category/216671.html

  2. CircleImageView自定义圆形控件的使用

    1.自定义圆形控件github地址: https://github.com/hdodenhof/CircleImageView 主要的类: package de.hdodenhof.circleima ...

  3. 剑指offer-面试题5.从尾到头打印链表

    题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值. 刚看到这道题的小伙伴可能就会想,这还不简单,将链表反转输出. 但是这种情况破坏了链表的结构. 如果面试官要求不破坏链表结构呢,这时候我们 ...

  4. yum安装配置mongoDB客户端和服务器端

    1,Centos6.X yum安装mongoDB客户端和服务器端; yum -y install mongodb mongodb-server; 基于epel repo.当前的mongoDB的版本为2 ...

  5. Sonar入门(一):简介

    什么是Sonar? Sonar是一个开源的代码质量管理平台.它能对代码进行如下7个维度的管理. 使用插件,它可以对20多种语言进行代码质量管理,这其中包括Java,C#,C/C++,PL/SQL等等. ...

  6. AFNetWorking网络请求

    NetWorkAPIClient.h #import <Foundation/Foundation.h> #import "AFHTTPRequestOperationManag ...

  7. 数据连接池——JNDI

    数据库连接有很多中方式,JDBC数据库的连接方式,前边我们已经介绍过了,而开发中我们经常使用的是DataBaseConnectionPool(数据库连接池,DBCP).数据库连接池到底是什么?它比jd ...

  8. DNA Sorting(排序)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  9. POJ 1987 Distance Statistics(树的点分治)

      转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 上场CF的C题是一个树的分治... 今天刚好又 ...

  10. rabbitmq-c初探

    RabbitMQ着实是个好东西,当然了也有对C语言client开发的支持.例子和文档少的可怜,只能去项目里去查看example来理解,简单整理了一些,以免走些弯路.主要是在版本对应上,这点就没Mave ...