codeforces 459 C. Pashmak and Buses(思维)
题目链接: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(思维)的更多相关文章
- 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, ...
- codeforces 459 A. Pashmak and Garden 解题报告
题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...
- codeforces 459 B.Pashmak and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...
- codeforces 459 E. Pashmak and Graph(dp)
题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- CodeForces - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Django settings.py 配置文件详解
settings.py 配置文件 import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) #引 ...
- memCached的配置文件 配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- restapi(3)- MongoDBEngine : MongoDB Scala编程工具库
最近刚好有同事在学习MongoDB,我们讨论过MongoDB应该置于服务器端然后通过web-service为客户端提供数据的上传下载服务.我们可以用上节讨论的respapi框架来实现针对MongoDB ...
- Docker笔记(七):常用服务安装——Nginx、MySql、Redis
开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的安装方法,一般都相对比较繁琐 —— 要经过下载软件或源码包,编译安装,配置,启动等步骤,使用 Docker ...
- java学习-NIO(三)Channel
通道(Channel)是java.nio的第二个主要创新.它们既不是一个扩展也不是一项增强,而是全新.极好的Java I/O示例,提供与I/O服务的直接连接.Channel用于在字节缓冲区和位于通道另 ...
- 关于 IntelliJ 的 IDEA PyCharm 等更新 2019.2 后中文乱码 的解决方案
关于IntelliJ 的2019.2 更新后的中文乱码解决方案 设置 备用字体 file -> Setting -> Editor ->Font 由于编程常用英文首选字体font默认 ...
- pythonday06数据类型(四)
今日内容 1.集合 2内存相关 1.集合set 无序 无重复 v = {1,2,3,4,5,6,99,100} # 疑问:v = {} """ None int v1 = ...
- ZooKeeper实现同步屏障(Barrier)
按照维基百科的解释:同步屏障(Barrier)是并行计算中的一种同步方法.对于一群进程或线程,程序中的一个同步屏障意味着任何线程/进程执行到此后必须等待,直到所有线程/进程都到达此点才可继续执行下文. ...
- win10文件备份、文件同步方案
用个人版onedrive同步重要数据,数据安全有保障,但免费版只有15G空间,需要合理分配.(201907与别人合租家庭版,空间1T充足) google-drive可以同步指定的文件夹,但空间也只有1 ...
- 源码分析Retrofit请求流程
Retrofit 是 square 公司的另一款广泛流行的网络请求框架.前面的一篇文章<源码分析OKHttp执行过程>已经对 OkHttp 网络请求框架有一个大概的了解.今天同样地对 Re ...