题目链接: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. spring boot 学习笔记之前言----环境搭建(如何用Eclipse配置Maven和Spring Boot)

    本篇文档来源:https://blog.csdn.net/a565649077/article/details/81042742 1.1 Eclipse准备 (1)     服务器上安装JDK和Mav ...

  2. 夯实Java基础(六)——包装类

    1.包装类简介 我们都知道Java是面向对象编程语言,包含了8种基本数据类型,但是这8种基本数据类型并不支持面向对象的特征,它们既不是类,也不能调用方法.这在实际使用时存在很多的不便,比如int类型需 ...

  3. JS 中构造函数和普通函数的区别

    原来只是随意的了解了下 , 但是最近有点忘了 于是详细了解下 加深下印象. 1.构造函数也是一个普通函数,创建方式和普通函数一样,但构造函数习惯上首字母大写 2.构造函数和普通函数的区别在于:调用方式 ...

  4. SpringMVC的流程

    Springmvc的流程 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求后,调用HandlerMapping处理映射器,请求获取Hand ...

  5. MyBatis 二级缓存全详解

    目录 MyBatis 二级缓存介绍 二级缓存开启条件 探究二级缓存 二级缓存失效的条件 第一次SqlSession 未提交 更新对二级缓存影响 探究多表操作对二级缓存的影响 二级缓存源码解析 二级缓存 ...

  6. C++基础之:扫雷破解

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  7. 【0809 | Day 12】可变长参数/函数的对象/函数的嵌套/名称空间与作用域

    可变长参数 一.形参 位置形参 默认形参 二.实参 位置实参 关键字实参 三.可变长参数之* def func(name,pwd,*args): print('name:',name,'pwd:',p ...

  8. Codeforces 436D Pudding Monsters

    题意简述 开始有无限长的一段格子,有n个格子种有布丁怪兽,一开始连续的布丁怪兽算一个布丁怪兽. 每回合你可以将一个布丁怪兽向左或右移动,他会在碰到第一个布丁怪兽时停下,并与其合并. 有m个特殊格子,询 ...

  9. 搞懂Go垃圾回收

    本文主要介绍了垃圾回收的概念,Golang GC的垃圾回收算法和工作原理,看完本文可以让你对Golang垃圾回收机制有个全面的理解.由于本人不了解其他语言的GC,并未对比其他语言的垃圾回收算法,需要的 ...

  10. PL/SQL 调用 JAVA代码

    1.直接在 SQL Developer中写入代码 create or replace and compile java source named "HelloWorld" as p ...