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

打印终于结果时设第一列就为1 1 1 1 ... 1,然后依次每列添加1后(公交车编号从1開始,不是从0開始) 。注意,这里是k进制。

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std; int tmpvalue[1001][1001]; int main()
{
#ifdef _DEBUG
freopen("d:\\in.txt", "r", stdin);
#endif
int n, k, d;
scanf("%d %d %d", &n, &k, &d);
if (k < n)
{
int total = 1;
for (int i = 1; i <= d;i++)
{
total *= k;
if (total >= n)
{
break;
}
}
if (total < n)
{
printf("-1\n");
return 0;
}
}
for (int i = 1; i <= d;i++)
{
tmpvalue[i][1] = 1;
}
for (int i = 2; i <= n;i++)
{
for (int j = 1; j <= d;j++)
{
tmpvalue[j][i] = tmpvalue[j][i - 1];
}
tmpvalue[1][i] += 1;
for (int j = 1; j <= d; j++)
{
if (tmpvalue[j][i] > k)
{
tmpvalue[j][i] = 1;
tmpvalue[j + 1][i]++;
}
else
break;
}
}
for (int i = 1; i <= d;i++)
{
for (int j = 1; j <= n;j++)
{
printf("%d ", tmpvalue[i][j]);
}
printf("\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

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

  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. 打印全排列和stl::next_permutation

    打印全排列是个有点挑战的编程问题.STL提供了stl::next_permutation完美的攻克了这个问题. 可是,假设不看stl::next_permutation,尝试自己解决,怎么做? 非常自 ...

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

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

  8. codeforce Pashmak and Buses(dfs枚举)

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

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

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

随机推荐

  1. C#图解教程学习笔记——委托

    一.委托概述委托和类一样,是用户自定义类型,也是引用类型.但类表示的是数据和方法的集合,而委托持有一个或多个方法,以及一系列预定义操作. 可以通过以下操作步骤来使用委托:(1)声明一个委托类型.委托声 ...

  2. 二、Ubuntu 转换为root用户

    用设置的用户登录进入. 输入以下命令 1--->su root 2--->sudo passwd root 输入root 用户密码 3--->su root    转换为root用户 ...

  3. .NET 下二维码解决方案

    使用Zint和Zxing实现二维码的编码与解码(Using open-source tools to generate and decode Q-R code) 1.Zint生成二维码 http:// ...

  4. 2016集训测试赛(十八)Problem C: 集串雷 既分数规划学习笔记

    Solution 分数规划经典题. 话说我怎么老是忘记分数规划怎么做呀... 所以这里就大概写一下分数规划咯: 分数规划解决的是这样一类问题: 有\(a_1, a_2 ... a_n\)和\(b_1, ...

  5. ArcObject开发,程序编译通过,但无法启动的解决

    在ArcGIS 二次开发时,我们很容易就会忽略了,授权方面的问题,尤其是初学者.这方面的问题的解决,主要有: (1)在ArcGIS object控件出现的Form窗体,上添加License Contr ...

  6. Mac搭建python环境

    1 安装xcode 2 安装 brew ruby-e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mast ...

  7. Flutter开发记录part3

    (1) 获取当前屏幕宽度 width: MediaQuery.of(context).size.width, (1) pull_to_refresh,smartrefresh 自定义文字: new S ...

  8. IntelliJ IDEA启动加速

    IntelliJ IDEA启动加速 学习了:https://blog.csdn.net/xiaosheng_papa/article/details/50378033 需要把插件都不加载就会快一些: ...

  9. spring boot 读取配置文件(application.yml)中的属性值

    在spring boot中,简单几步,读取配置文件(application.yml)中各种不同类型的属性值: 1.引入依赖: <!-- 支持 @ConfigurationProperties 注 ...

  10. Android中的Telephony学习笔记(2)

    上一篇文章中学习了android.provider中Telephony类. 这一篇文章学习android.telephony包中的类,这些类是android提供给上层调用的API. 为监測基本电话信息 ...