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\)条边,使得 ...
随机推荐
- 水题 J
一张CT扫描的灰度图像可以用一个N*N(0 < N <= 100)的矩阵描述,矩阵上的每个点对应一个灰度值(整数),其取值范围是0-255.我们假设给定的图像中有且只有一个肿瘤.在图上监测 ...
- DataRow 点不出 Select
DataRow 点不出 Select?why?using system.linq;
- Vue系列之 => 组件切换
组件切换方式一 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- Sitecore xDB基础知识 - 识别用户,联系人,访客,客户
体验数据库(xDB)是Sitecore平台的关键元素,特别是当您希望将解决方案提升到简单的内容管理要求之外时.它用于跟踪您的用户(即联系人,访客,客户)与您网站的互动方式.营销人员可以使用此数据来了解 ...
- Spring boot jackson
Spring boot 所引用的包里面包含 jackson-databind-2.8.3.jar jackson-annotations-2.8.3.jar jackson-core-2.8.3.ja ...
- 设计模式之Command(命令)(转)
Command模式是最让我疑惑的一个模式,我在阅读了很多代码后,才感觉隐约掌握其大概原理,我认为理解设计模式最主要是掌握起原理构造,这样才对自己实际编程有指导作用.Command模式实际上不是个很具体 ...
- mysql安装使用
linux系统 mysql-5.7.14-linux.zip部署包支持在CentOS 6.x/7.x 服务器硬盘大小要求 a) /data/mysql_data 如果存在该独立分区,要求该分区 &g ...
- js中的children实时获取子元素
先看下面一个小例子的结果 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- Android4.0 主线程不能访问网络异常解决办法
从两个方面说下这个问题: 1. 不让访问网络的原因 2. 解决该问题的办法 不让访问网络的原因: 由于对于网络状况的不可预见性,很有可能在网络访问的时候造成阻塞,那么这样一来我们的主线程UI线程 就会 ...
- <转>jmeter(四)HTTP请求
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...