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 爬qidian小说
import re import urllib.request from bs4 import BeautifulSoup import time url=input("第一章网址:&quo ...
- Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。
解决办法如下: 1.在_Layout.cshtml布局body内,添加section,Scripts.Render和RenderSection标签示例代码如下: <body class=&quo ...
- datatable的点击事件
datatable的点击事件 在项目中遇到一个问题,在动态绑定到datatables上的数组,要是用table中的两个某一行中数据作为参数,通过鼠标点击进行获取,查阅官方文档得以解决: //首先定义一 ...
- plsql连接远程oracle数据库
1.在oracle安装目录D:\app\Eric\product\11.2.0\dbhome_1\NETWORK\ADMIN找到tnsnames.ora:2.ORCL =(DESCRIPTION = ...
- 电脑已连接wifi的密码查询
有时候,想登陆自己家的无线网络(尤其朋友来家里突然要连接无线网络),脑子刹那间一片空白想不起来密码,怎么办呢? 其实,我们可以通过电脑来查看网络的密码,现在分享如何在笔记本电脑上查看连接过的无线网络密 ...
- 基础 MySQL
.一.MySQL概述 1.什么是数据库 答:数据的仓库,如:在ATM的示例中我们创建了一个 DB 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL ...
- VIM For Windows 1
some tips for using vim in windows. 1,download the software vim and install it, you can go to the Of ...
- Hive批量删除历史分区
批量删除历史分区和数据可以采用如下操作: -- 删除20180101之前的所有分区 alter table example_table_name drop if exists partition (d ...
- C# 调整控件的Z顺序
当窗口或者容器控件中的控件在布局过程中发生重叠的时候,会出现层次性.Z顺序较大的控件会遮挡Z顺序较小的控件,放在顶层的控件会挡住放在底层的控件. 1.编辑一个这样的窗口(使用Label控件) 2.添加 ...
- golang学习笔记9 beego nginx 部署 nginx 反向代理 golang web
golang学习笔记9 beego nginx 部署 nginx 反向代理 golang web Nginx 部署 - beego: 简约 & 强大并存的 Go 应用框架https://bee ...