Codeforces 459C Pashmak and Buses 机智数学题
这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可。
要你求是否有这样的安排方法,如果有,输出具体的安排方案,每个人每天坐那辆车。
挺不错的题目,我压根没想到。。真的,虽然知道之后惊呼原来如此简单,但一开始确实想岔了。现在一看这题目,很清晰,每个学生在这m天中坐的车辆,就会形成一个由m个数字组成的序列(数字为1-k代表巴士编号),按照题目要求,只需要学生的那个序列是独一无二的即可。
那么,我们只要把题意转化为 求n个不同的m个数字组成的序列(只要有一个数字不同即为不同),那么我们把这个序列,认为是一个 m位的k进制的数不就行了,每次从111111.。
开始枚举,一直枚举到kkkkkk。。。结束啊啊。。。哎,真的很机智的题诶
当然一开始可以直接乘一下判断m个k进制的数是否>=n,不满足直接输出-1,满足就用类似高精度加法把序列求出来再输出即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std;
LL n,k,d;
int ans[][];
int main()
{
while (scanf("%I64d%I64d%I64d",&n,&k,&d)!=EOF)
{
LL tmp=k;
for (LL i=;i<=d;i++){
tmp=tmp*k;
if (tmp>=n) break;
}
if (tmp<n){
puts("-1");
continue;
}
for (int i=d;i>=;i--) ans[][i]=;
ans[][d]=;
for (int i=;i<=n;i++){
int c=;
ans[i][d]=ans[i-][d]+;
if (ans[i][d]>k){ans[i][d]=;c++;}
for (int j=d-;j>=;j--){
ans[i][j]=ans[i-][j]+c;
if (ans[i][j]>k){
c=;
ans[i][j]=;
}
else c=;
}
}
for (int i=;i<=d;i++){
printf("%d",ans[][i]);
for (int j=;j<=n;j++){
printf(" %d",ans[j][i]);
}
puts("");
}
}
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辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- 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 ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
随机推荐
- jforum发表文章和回复文章显示中文乱码问题
jforum安装时,在数据库创建jforum数据库的时候,设置了字符集(CREATE DATABASE jforum DEFAULT CHARACTER SET utf8 COLLATE utf8_g ...
- ORM常用字段及查询
目录 ORM常用字段及参数 创建表 ORM常用字段 ORM字段参数 ORM表关系创建 ForeignKey OneToOneField ManyToManyField 多对多三种创建方式 单表查询 q ...
- SDL 显示汉字
#include "stdafx.h" #pragma comment(lib,"SDL.lib") #pragma comment(lib,"SDL ...
- ROS学习笔记11-写一个简单的服务和客户端(C++版本)
本文主要来源于:http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29 写一个服务节点.在创建消息和服务中,我们创建了一 ...
- XML中报错
错误描述如下: Multiple annotations found at this line: - cvc-complex-type.2.4.a: Invalid content was found ...
- 「Luogu1901」发射站
传送门 Luogu 解题思路 单调栈裸题,扫两遍处理出每个点左边第一个比他高的和右边第一个比他高的,然后模拟题意即可. 细节注意事项 咕咕咕. 参考代码 #include <algorithm& ...
- 【高软作业3】:原型化系统 DevTools
原型化系统:DevTools 密码:lcx 1. 这是一个什么样的平台? DevTools,可译为:开发者工具库.初衷是聚集各类开发工具,方便开发者获取:此外,大家可以分享自己的工具库与工 ...
- 085、Java数组之实现排序
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- yarn container 的日志路径
/etc/hadoop/conf/yarn-site.xml 配置文件中 - yarn.nodemanager.log-dirs 指定本机的日志路径 (/hadoopfs/fs1/yarn/nodem ...
- dataset的reparation和coalesce
/** * Returns a new Dataset that has exactly `numPartitions` partitions, when the fewer partitions * ...