题目链接:http://codeforces.com/problemset/problem/459/C

题意:有n个人,k辆车,d天要求没有两个人在d天都坐在一起。输出坐的方法。

题解:这题很有意思,首先在这d天里每个人都有一个序列那就是每天坐哪辆车。然后为了满足题意只要他们

的序列都是独一无二的就行。也就是说k辆车,d天总共有k^d次方的坐法,所以最多能提供k^d个人。然后

就是怎么输出了,这有一个技巧,只要构成d位的k进制数就行。然后遍历1~n依次加1即可。

#include <iostream>
#include <cstring>
using namespace std;
int a[2000][2000];
int main() {
int n , k , d;
cin >> n >> k >> d;
int flag = 0;
long long sum = 1;
for(int i = 1 ; i <= d ; i++) {
sum *= k;
if(sum >= n) {
flag = 1;
break;
}
}
if(flag) {
for(int j = 1 ; j <= d ; j++) {
a[1][j] = 1;
}
for(int i = 2 ; i <= n ; i++) {
int tmp = 0;
for(int j = d ; j >= 1 ; j--) {
if(tmp) {
a[i][j] = a[i - 1][j];
continue;
}
if(a[i - 1][j] + 1 <= k) {
a[i][j] = a[i - 1][j] + 1;
tmp = 1;
}
else {
a[i][j] = 1;
}
}
}
for(int i = 1 ; i <= d ; i++) {
for(int j = 1 ; j <= n ; j++) {
cout << a[j][i] << ' ';
}
cout << endl;
}
}
else {
cout << -1 << endl;
}
return 0;
}

codeforces 459 C. Pashmak and Buses(思维)的更多相关文章

  1. codeforces 459 D. Pashmak and Parmida's problem(思维+线段树)

    题目链接:http://codeforces.com/contest/459/problem/D 题意:给出数组a,定义f(l,r,x)为a[]的下标l到r之间,等于x的元素数.i和j符合f(1,i, ...

  2. codeforces 459 A. Pashmak and Garden 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...

  3. codeforces 459 B.Pashmak and Flowers 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...

  4. codeforces 459 E. Pashmak and Graph(dp)

    题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...

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

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

  6. CodeForces - 459C - Pashmak and Buses

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

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

  8. cf 459c Pashmak and Buses

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

  9. cf459C Pashmak and Buses

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

随机推荐

  1. 云计算网络基础笔记及VLAN交换机配置

  2. java基本数据类型和包装类之间的区别

    1.声明方式不同,基本类型不适用new关键字,而包装类型需要使用new关键字来在堆中分配存储空间: 2.存储方式及位置不同,基本类型是直接将变量值存储在堆栈中,而包装类型是将对象放在堆中,然后通过引用 ...

  3. 数据结构之稀疏矩阵C++版

    //只是简单的演示一下,这个实际运用视乎不怎么多,所以java版不再实现 /* 希疏矩阵应用于对数据的压缩,仅仅保留不为0的数据 稀疏矩阵的转置,可以由多种方式,下面演示的稍显简单,时间复杂度略高O( ...

  4. java高并发系列 - 第25天:掌握JUC中的阻塞队列

    这是java高并发系列第25篇文章. 环境:jdk1.8. 本文内容 掌握Queue.BlockingQueue接口中常用的方法 介绍6中阻塞队列,及相关场景示例 重点掌握4种常用的阻塞队列 Queu ...

  5. ZooKeeper系列(二)—— Zookeeper 单机环境和集群环境搭建

    一.单机环境搭建 1.1 下载 下载对应版本 Zookeeper,这里我下载的版本 3.4.14.官方下载地址:https://archive.apache.org/dist/zookeeper/ # ...

  6. 02 http和https协议

    1. HTTP协议 简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写, 是用于从万维网(WWW:World Wide Web )服务器传输超文本到本 ...

  7. xpath中normalize-space的用法【转载】

    下面这个菜单中,要点击“货运表现”,我们来看一下xpath, 菜单中的所有项的id都是“vertab”,所以不能用id来定位,那么先用文本的xpath试试 //a[text()='货运表现'] 发现定 ...

  8. egret项目发布为微信小程序

    1.更改游戏的缩放模式 因为微信小游戏不支持showAll,如果你使用了showAll模式.可以改成fixedWidth或fixedHeight.在index.html里修改,如下图 但这个又涉及到了 ...

  9. python 16 模块

    目录 模块 1. 自定义模块 1.1 模块分类 1.2 模块的导入 1.3 import 和 from 1.4 from 模块名 import * 1.5 模块的用法: 1.6 导入路径 2. tim ...

  10. Count the string[KMP]HDU3336

    题库链接http://acm.hdu.edu.cn/showproblem.php?pid=3336 这道题是KMP的next数组的一个简单使用,首先要理解next数组的现实意义:next[i]表示模 ...