Codeforces Round #261 (Div. 2) C
Description
Recently Pashmak has been employed in a transportation company. The company has kbuses 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.
The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).
If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print nintegers. The j-th integer of the i-th line shows which bus the j-th student has to take on thei-th day. You can assume that the buses are numbered from 1 to k.
3 2 2
1 1 2
1 2 1
3 2 1
-1
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.
题意:有K台公交,n个人,d天,任意两个人全部d天都不能做同一辆公交,输出这种安排
解法:K台公交安排d天,自然是Kd种方法,Ki大于等于n说明符合要求,再将1~n变成k进制保证题目要求,然后按照题目要求输出
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll Pow(ll a,ll b)
{
ll ans=;
ll base=a;
while(b)
{
if(b&)
{
ans*=base;
}
base*=base;
b>>=;
}
return ans;
}
ll n,k,d;
ll solve[][];
int main()
{
int flag=;
cin>>n>>k>>d;
for(int i=;i<=d;i++)
{
if(Pow(k,i)>=n)
{
flag=;
break;
}
}
if(flag)
{
for(int i=;i<=n;i++)
{
ll num=i;
for(int j=;j<=d;j++)
{
solve[i][j]=num%k+;
num/=k;
}
}
for(int i=;i<=d;i++)
{
for(int j=;j<=n;j++)
{
cout<<solve[j][i]<<" ";
}
cout<<endl;
}
}
else
{
cout<<"-1"<<endl;
}
return ;
}
Codeforces Round #261 (Div. 2) C的更多相关文章
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces Round #261 (Div. 2) - E (459E)
题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...
- Codeforces Round #261 (Div. 2)
第一场难得DIV2简单+AK人数多: E:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ...
随机推荐
- block-循环引用
在ARC机制下,app的内存管理由操作系统进行管理,不须要程序猿手动的管理内存,方便了开发.虽然,自己主动释放内存非常方便.可是并不是绝对安全,绝对不会产生内存泄露. 大部分导致iOS对象无法按预期释 ...
- MD5加密实现类不是Windows平台下联邦信息处理标准验证过的加密算法的一部分
在.NET应用程序中,MD5CryptoServiceProvider实例化时,造成This implementation is not part of the Windows Platform FI ...
- 把node加入master节点时,日志内容分析
root@node1:~# kubeadm --token bggbum.mj3ogzhnm1wz07mj --discovery-token-ca-cert-hash sha256:8f02f833 ...
- Mahout 0.5部署
Mahout下载与安装 1.下载Mahout.到地址[1]可以找到镜像地址.我们下载Mahout 0.5.请将mahout-distribution-0.5.tar.gz和mahout-distrib ...
- 中国vs美国制造业公司营业额大排名,看看哪些属于美国制造业的优势产业(中美旗鼓相当,而且还有本土制造的优势)
当然,所谓的美国制造业,大量的东西现在 在中国制造和生产,但这里列举的,主要是卖实体工业产品为主的美国公司这个榜单里主要列出以工业产品销售为主的公司. 所以各大能源巨头虽然本身也是装备制造大户,但没被 ...
- R学习-- 数组和矩阵
生成 4行5列的数组,逐列逐行赋值x = array(1:20, dim= c(4,5)) 依据已知向量生成二维数组i = array(c(1:3,3:1,4:6,5:7), dim=c(3,4))也 ...
- 安装mysql 8.0版本时,使用front连接报1251错误或者navicat 连接报错2059解决方案
这个错误出现的原因是在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password. 解决此问题有两种方法, ...
- Java DES加密解密
import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpe ...
- 为了cider,尝试emacs的坑
https://github.com/clojure-emacs/cider http://clojure-doc.org/articles/tutorials/emacs.html emacs通过b ...
- Hihocoder #1077 : RMQ问题再临-线段树(线段树:结构体建树+更新叶子往上+查询+巧妙使用father[]+线段树数组要开大4倍 *【模板】)
#1077 : RMQ问题再临-线段树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到:小Hi给小Ho出了这样一道问题:假设整个货架上从左到右摆放了N种商品,并 ...