codeforces 459 C. Pashmak and Buses(思维)
题目链接:http://codeforces.com/problemset/problem/459/C
题意:有n个人,k辆车,d天要求没有两个人在d天都坐在一起。输出坐的方法。
题解:这题很有意思,首先在这d天里每个人都有一个序列那就是每天坐哪辆车。然后为了满足题意只要他们
的序列都是独一无二的就行。也就是说k辆车,d天总共有k^d次方的坐法,所以最多能提供k^d个人。然后
就是怎么输出了,这有一个技巧,只要构成d位的k进制数就行。然后遍历1~n依次加1即可。
#include <iostream>
#include <cstring>
using namespace std;
int a[2000][2000];
int main() {
int n , k , d;
cin >> n >> k >> d;
int flag = 0;
long long sum = 1;
for(int i = 1 ; i <= d ; i++) {
sum *= k;
if(sum >= n) {
flag = 1;
break;
}
}
if(flag) {
for(int j = 1 ; j <= d ; j++) {
a[1][j] = 1;
}
for(int i = 2 ; i <= n ; i++) {
int tmp = 0;
for(int j = d ; j >= 1 ; j--) {
if(tmp) {
a[i][j] = a[i - 1][j];
continue;
}
if(a[i - 1][j] + 1 <= k) {
a[i][j] = a[i - 1][j] + 1;
tmp = 1;
}
else {
a[i][j] = 1;
}
}
}
for(int i = 1 ; i <= d ; i++) {
for(int j = 1 ; j <= n ; j++) {
cout << a[j][i] << ' ';
}
cout << endl;
}
}
else {
cout << -1 << endl;
}
return 0;
}
codeforces 459 C. Pashmak and Buses(思维)的更多相关文章
- codeforces 459 D. Pashmak and Parmida's problem(思维+线段树)
题目链接:http://codeforces.com/contest/459/problem/D 题意:给出数组a,定义f(l,r,x)为a[]的下标l到r之间,等于x的元素数.i和j符合f(1,i, ...
- codeforces 459 A. Pashmak and Garden 解题报告
题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...
- codeforces 459 B.Pashmak and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...
- codeforces 459 E. Pashmak and Graph(dp)
题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...
- 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 - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题
A.题意就是把字符串里面的数字按增序排列,直接上代码. #include <string.h> #include <stdio.h> #include <algorith ...
- Qt Socket 收发图片——图像拆包、组包、粘包处理
之前给大家分享了一个使用python发图片数据.Qt server接收图片的Demo.之前的Demo用于传输小字节的图片是可以的,但如果是传输大的图片,使用socket无法一次完成发送该怎么办呢?本次 ...
- Docker笔记(七):常用服务安装——Nginx、MySql、Redis
开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的安装方法,一般都相对比较繁琐 —— 要经过下载软件或源码包,编译安装,配置,启动等步骤,使用 Docker ...
- 【Java例题】4.3 3. 使用Gauss消元法求解n元一次方程组的根,
3. 使用Gauss消元法求解n元一次方程组的根,举例,三元一次方程组:0.729x1+0.81x2+0.9x3=0.6867x1+x2+x3=0.83381.331x1+1.21x2+1.1x3=1 ...
- 【Java例题】4.4使用牛顿迭代法求方程的解
4. 使用牛顿迭代法求方程的解:x^3-2x-5=0区间为[2,3]这里的"^"表示乘方. package chapter4; public class demo4 { publi ...
- 【游记】NOIP2019初赛
声明 我的游记是一个完整的体系,如果没有阅读过往届文章,阅读可能会受到障碍. ~~~上一篇游记的传送门~~~ 前言 (编辑中) 文章推荐:[游记]NOIP2019复赛
- 【0725 | Day 1】计算机编程/计算机组成原理/计算机操作系统
什么是编程 编程语言:人与计算机交流的手段 编程:通过编程语言编写文件 学习编程的目的:让计算机代替人力,为我们服务 计算机组成原理 计算机由五大部分组成:控制器.运算器.存储器.输入设备.输出设备. ...
- javaweb基础整理随笔-----上传与下载步骤详解
这次整理的是上传与下载的原生代码解析: 上传:1.对页面的要求:enctype="multipart/form-data" method="post" ...
- Python模拟登录淘宝
最近想爬取淘宝的一些商品,但是发现如果要使用搜索等一些功能时基本都需要登录,所以就想出一篇模拟登录淘宝的文章!看了下网上有很多关于模拟登录淘宝,但是基本都是使用scrapy.pyppeteer.sel ...
- Nginx 1.15.5: 405 Not Allowed
0x00 事件 在做一个业务跳转时,遇到这个错误 405 Not Allowed,找了挺多资料,多数解决方案是让在 nginx 配置文件中直接添加 error_page 405 =200 $uri; ...