CF459C Pashmak and Buses (构造d位k进制数
Codeforces Round #261 (Div. 2)
| C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days. Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity. Input The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). Output If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k. Sample test(s) Input 3 2 2 Output 1 1 2 Input 3 2 1 Output -1 Note Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day. | 
题意:输入n k d,n个人坐k辆车过d天,要求没有2个人是每天都在一辆车上的。若不可能,输出-1;否则输出每个人每天坐哪趟车。
题解:
一个人在全部d天中每天坐哪辆车,可以表示为d位k进制数x。那么2个人每天都在同一辆车上,就是两个人的x相等。所以我们只要构造出n个不同的d位k进制数就行。
先判若d^k<n则无解。(注意用(int)pow(5,4)会得比实际结果小1的整数……pow还是用double来撸比较好)
然后就撸出n个d位k进制数,我是直接0~n-1,转换成k进制数。
最后输出,我是由0~k-1组成的k进制数,输出时加1就行。
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair
int n,k,d;
int a[][];
bool farm(){
int i;
if((double)n > (pow((double)k,d)))return ;
memset(a,,sizeof(a));
for(i=;i<n;i++){
int x=i,j=;
while(x){
a[i][j++]=x%k;
x/=k;
}
}
return ;
} int main(){
int i,j;
scanf("%d%d%d",&n,&k,&d);///人数、车数、天数
///搞n个不同的d位k进制数,作为n个学生d天坐的车
int ans=farm();
if(ans==)puts("-1");
else{
for(i=;i<d;i++){
printf("%d",a[][i]+);
for(j=;j<n;j++){
printf(" %d",a[j][i]+);
}
puts("");
} }
return ;
}
CF459C Pashmak and Buses (构造d位k进制数的更多相关文章
- P1066 2^k进制数
		传送门 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进 ... 
- 洛谷 P1066 2^k进制数
		P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. ( ... 
- 一本通1649【例 2】2^k 进制数
		1649:[例 2]2^k 进制数 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:NOIP 2006 提高组 设 r 是个 2k 进制数,并满足以 ... 
- 蓝桥杯   问题  1110:   2^k进制数    (排列组合+高精度巧妙处理)
		题目链接 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2 ... 
- 洛谷P1066 2^k进制数
		P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. ( ... 
- [NOIP2006] 提高组 洛谷P1066 2^k进制数
		题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后 ... 
- [luogu]P1066 2^k进制数[数学][递推][高精度]
		[luogu]P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻 ... 
- 【洛谷p1066】2^k进制数
		(不会敲键盘惹qwq) 2^k进制数[传送门] 算法标签: (又是一个提高+省选-的题) 如果我说我没听懂你信吗 代码qwq: #include<iostream> #include< ... 
- 汇编:1位16进制数到ASCII码转换
		;============================ ;1位16进制数到ASCII码转换 ; { X+30H (0≤X≤9) ;Y= { ; { X+37H (0AH≤X≤0FH) DATAS ... 
随机推荐
- Top K 问题
			Example Given [3,10,1000,-99,4,100] and k = 3. Return [1000, 100, 10]. 解法有以下几种: 1. bubble sort k tim ... 
- Linq集合
			摘要:微软在.NET 3.5中推出了LINQ,现在各种LINQ Provider满天飞,TerryLee在老外站点上收集了一份LINQ Provider列表 微软在.NET 3.5中推出了LINQ,现 ... 
- 关于win7上内存占用较大的说明
			1 Win7系统较XP系统内存占用高: 由于xp系统属于轻量化的系统,而win7系统是一个重量型的系统,在两者的内存管理机制上有很大的区别,根据业界和微软对外的发布公告中可以看到,win7系 ... 
- K米评测
			调研,评测 1)评测 体验: 流畅度不足. 遥控按钮太过偏右,对大屏手机用户不够友好. ui风格不统一,矩形,圆角矩形,圆形混用,圆角矩形的圆角半径也不相同. 状态栏不是沉浸式的,观感较差,特别是白色 ... 
- 高可用与负载均衡(6)之聊聊LVS的三种模式
			LVS的赘述 IPVS,ipvs ,ip_vs是负载均衡器中的内核代码 LVS是完整的负载均衡器+后端服务器.这些组件组成了虚拟服务器. LVS是一个4层负载均衡方案,标准的客户端-服务器网络语义也被 ... 
- python运维开发坎坷之路-01
			前言 2014年9月,新疆乌鲁木齐,在51CTO学院看着alex老师的python教学视频,不得不说这是我第一次接触python这门高级语言,从最开始的一无所知到现在能够用python写脚本,再到未来 ... 
- hihoCoder1284机会渺茫(唯一分解定理 + 约分)
			题目链接 #1284 : 机会渺茫 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在追求一名学数学的女生小Z.小Z其实是想拒绝他的,但是找不到好的说辞,于是提出 ... 
- python 处理CSV数据
			从CS中导入数据 Python中有一个CSV模块支持读写各种方言格式的CSV文件.方言是很重要的,因为没有一个同意的CSV标准,不同的应用实现CSV的方式略有不同,当看到文件的内容的时候你往往很容易第 ... 
- Can not issue data manipulation statements with executeQuery() 异常处理
			1.这个异常的报错翻译过来就是 不能发出数据操纵语句与executeQuery() 2.这里要检查一下你要执行的实际SQL语句要做什么操作 查询呢?还是修改? 3.如果是修改的话,需要添加@Modif ... 
- SOCKADDR_IN
			在windows/linux下有下面结构: sockaddr结构 struct sockaddr { unsigned short sa_family;/*addressfamily,AF_xxx*/ ... 
