题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1

思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车、第二天1号车、第三天2号车、第四天3号车,那么就是求构造n个不相同的d位数,所以只要k>= n,然后模拟加一

代码:

#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = 1e3 + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
bool check(ll a, ll b, ll n){
ll ret = ;
while(b){
if(b & ) ret = ret * a;
a = a * a;
b >>= ;
if(ret >= n) return true;
}
return false;
}
int ans[maxn][maxn];
int main(){
int n, k, d;
scanf("%d%d%d", &n, &k, &d);
if(check(min(k, n), d, n)){
for(int i = ; i <= d; i++)
ans[i][] = ;
for(int i = ; i <= n; i++){
int c = ; //进位
ans[][i] = ans[][i - ] + ;
if(ans[][i] > k){
ans[][i] = ;
c = ;
}
for(int j = ; j <= d; j++){
ans[j][i] = ans[j][i - ] + c;
c = ;
if(ans[j][i] > k){
ans[j][i] = ;
c = ;
}
}
}
for(int i = ; i <= d; i++){
for(int j = ; j <= n; j++){
if(j != ) printf(" ");
printf("%d", ans[i][j]);
}
printf("\n");
}
}
else printf("-1\n");
return ;
}

CodeForces 459C Pashmak and Buses(构造)题解的更多相关文章

  1. CodeForces - 459C - Pashmak and Buses

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

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

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

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

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

  4. Codeforces 459C Pashmak and Buses 机智数学题

    这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...

  5. cf 459c Pashmak and Buses

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

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

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

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

  8. Codeforces 1246D/1225F Tree Factory (构造)

    题目链接 https://codeforces.com/contest/1246/problem/D 题解 首先考虑答案的下界是\(n-1-dep\) (\(dep\)为树的深度,即任何点到根的最大边 ...

  9. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

随机推荐

  1. SQLGetEnvAttr

    SQLGetEnvAttr 函数定义: 用于得到当前环境的各项设置属性 SQLRETURN SQLGetEnvAttr( SQLHENV     EnvironmentHandle, SQLINTEG ...

  2. 大话设计模式C++ 适配器模式

    适配器模式:将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原来由于接口不兼容而不能一起工作的那些类可以一起工作. 角色: (1)Target:这是客户所期待的接口,Target可以 ...

  3. Python -- 连接数据库SqlServer

    用Python几行代码查询数据库,此处以Sql server为例. 1. 安装pymssql,在cmd中运行一下代码 pip install pymssql 2. 链接并执行sql语句 #-*-cod ...

  4. Linux——CentOS7安装gcc编译器详解

    使用yum安装gcc 使用yum命令安装还是非常easy的. yum -y install gcc gcc-c++ kernel-devel //安装gcc.c++编译器以及内核文件 手动安装gcc ...

  5. 使用js实现登录随机验证码的效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. mybatis源码解析1--前言

    在开始分析mybatis源码之前,需要定一个目标,也就是我们不是为了读源码而去读,一定是带着问题去读,在读的时候去寻找到答案,然后再读码的同时整理总结,学习一些高级的编码方式和技巧. 首先我们知道my ...

  7. 阿里巴巴 Java 代码规范

    1. 抽象类命名使用 Abstratc开头. 2. 阿里强制规定不允许任何魔法值(未经定义的常量)直接出现在代码中.魔法值会让代码的可读性大大降低,而且如果同样的数值多次出现时,容易出现不清楚这些数值 ...

  8. golang学习笔记18 用go语言编写移动端sdk和app开发gomobile

    golang学习笔记18 用go语言编写移动端sdk和app开发gomobile gomobile的使用-用go语言编写移动端sdk和app开发https://blog.csdn.net/u01249 ...

  9. go语言,golang学习笔记4 用beego跑一个web应用

    go语言,golang学习笔记4 用beego跑一个web应用 首页 - beego: 简约 & 强大并存的 Go 应用框架https://beego.me/ 更新的命令是加个 -u 参数,g ...

  10. system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

    elasticsearch启动时遇到的错误 这个是elasticsearch配置文件的问题. 解决办法: 在elasticsearch.yml配置文件中 添加     bootstrap.system ...