题意: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. Apache Storm Installation

    安装的过程参照此处的过程介绍(https://www.tutorialspoint.com/apache_storm/apache_storm_installation.htm) 安装的过程要安装3个 ...

  2. Visual Studio快捷键查询

    Ctrl+E,D —-格式化全部代码  Ctrl+E,F —-格式化选中的代码  CTRL + SHIFT + B生成解决方案  CTRL + F7 生成编译  CTRL + O 打开文件  CTRL ...

  3. c++ 常用的数据结构

    set // constructing sets #include <iostream> #include <set> void checkin(std::set<int ...

  4. windows假装更新升级

    http://fakeupdate.net/ 进入这个网站,选择一款系统界面,按F11进去全屏 比较有趣

  5. 如何让多个dz论坛共用一个用户数据库

    用户数据库在论坛中是可以独立备份的,备份方法:论坛后台——站长——数据库,备份所有ucenter数据表,也就是用户数据.其他DZ论坛搭建完成以后,可以上传用户数据库,将备份文件使用上传至网站所使用的主 ...

  6. CSS文本(Text)属性-----letter-spacing和text-align

       letter-spacing letter-spacing:normal | <length>  指定字符之间的额外间隙 normal:默认间隔.计算值为0 <length&g ...

  7. tr字符串的梗

    工作问题总结 声明:应用程序代码为前人所写,仅仅只是维护代码,暂且不论代码风格瑕疵. 结论: 使用tr“包”起来的字符串,可能会被翻译为不同的语言,此时,应用程序在不同语言环境下可能会表现BUG. 1 ...

  8. 激活win10

    网盘地址 http://pan.baidu.com/s/1nvc5I1V 里面是2个东西,一个是rar解压缩软件,一个是激活工具本体 一个解压缩软件,一个激活工具的压缩包 安装解压软件,就是WINRA ...

  9. 关于SQL语句中的distinct和group by

    两种都能实现去重功能.区别: distinct只是将重复的行从结果中出去: group by是按指定的列分组,一般这时在select中会用到聚合函数. distinct是把不同的记录显示出来 grou ...

  10. hibernate自动创建表报表不存在

    在hibernate.cfg.xml配置了<property name="hibernate.hbm2ddl.auto">update</property> ...