CodeForces 459C Pashmak and Buses(构造)题解
题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1
思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车、第二天1号车、第三天2号车、第四天3号车,那么就是求构造n个不相同的d位数,所以只要kd >= 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(构造)题解的更多相关文章
- CodeForces - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- codeforces 459C Pashmak and Buses(模拟,组合数A)
题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...
- Codeforces 459C Pashmak and Buses 机智数学题
这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 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 ...
- 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 1246D/1225F Tree Factory (构造)
题目链接 https://codeforces.com/contest/1246/problem/D 题解 首先考虑答案的下界是\(n-1-dep\) (\(dep\)为树的深度,即任何点到根的最大边 ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
随机推荐
- python将目录切换为脚本所在目录
os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
- arcgis api for js简要笔记
1.主要借助官网的接口文档和samplecode来学习 https://developers.arcgis.com/javascript/latest/api-reference/index.html ...
- python: numpy--函数 shape用法
http://blog.csdn.net/u010758410/article/details/71554224 shape函数是numpy.core.fromnumeric中的函数,它的功能是查看矩 ...
- mvc未登录跳转到登录界面
编写一个mvc控制器基类BaseController , 其继承自controller 重写其OnActionExecuting方法, 在其中检测session值,如果没有,则跳转至登录页面. 如下
- centos中yum命令删除还原的补救方法介绍
前言 yum,是Yellow dog Updater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow ...
- 使用yaml+groovy实现Java代码可配置化
背景与目标 在使用函数接口和枚举实现配置式编程(Java与Scala实现),使用了函数接口和枚举实现了配置式编程.读者可先阅读此文,再来阅读本文. 有时,需要将一些业务逻辑,使用配置化的方式抽离出来, ...
- python 安装pandas
1.pandas有啥用 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具.pand ...
- GUI常用对象介绍3
%text hf = axes; ht = text(,,'示例'); get(ht); %公式 并且设置位置坐标 (积分符号) text('String','\int_0^x dF(x)','Pos ...
- SQL SERVER镜像配置(包含见证服务器)
镜像简介 重要说明:保持数据库镜像运行.如果您关闭数据库镜像,则必须执行完全备份并还原数据库以重建数据库镜像. 一. 简介 SQL SERVER 2005镜像基于日志同步,可良好实现故障转移. ...
- Hadoop学习笔记之四:HDFS客户端
HDFS的客户端核心是DFSClient类,所有使用HDFS的客户端都会持有一个DFSClient对象,或通过持有一个DistributedFileSystem对象间接使用DFSClient: DFS ...