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:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ... 
随机推荐
- attribute constructor&destructor
			attribute constructor&destructor 在看openwrt里libnl-tiny这个库的时候,遇到了C里面的构造函数这个概念. static void __init ... 
- PandoraBox 支持3G无线上网卡(联通卡3G卡)(一)
			一:笔者采用的是系统是OpenWrt之PandoraBox,内核版本3.3.8:硬件设备是MTK的7620开发板. 其中怎么搭建openwrt开发环境在此不用多说,因为既然想实现3G无线上网卡拨号上网 ... 
- java语句顺序有时非常重要
			我们学习java时,通常被告知,变量定义的顺序不重要,可是下面程序确在jdk 1.7上执行出错. public class FactoryImpl implements Serializable { ... 
- POJ  2886 Who Gets the Most Candies?(树状数组+二分)
			题目链接 注意题目中给的顺序是顺时针的,所以在数组中应该是倒着存的.左就是顺时针,右就是逆时针.各种调试之后,终于A了,很多种情况考虑情况. #include <cstring> #inc ... 
- hdfs 3种 通讯协议
			http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 通讯协议 所有的HDFS通讯协议都是建立在TCP/IP协议之上.客户端通过一个可配置的 ... 
- Axure Base 01
			名词解释: 线框图:一般就是指产品原型,比如:把线框图尽快画出来和把原型尽快做出来是一个意思. axure元件:也叫axure组件或axure部件,系统自带了一部分最基础常用的,网上也有很多别人做好的 ... 
- 用Qt编写的计算文件MD5值的Demo
			Dialog.ui <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0& ... 
- ubuntu 本地和服务器scp文件传输
			安装 SSH(Secure Shell) 服务以提供远程管理服务 sudo apt-get install ssh SSH 远程登入 Ubuntu 机 ssh username@192.168.0.1 ... 
- [Android6.0][RK3399] 修改默认按键 KEY-PAD 的功能【转】
			本文转载自:http://m.blog.csdn.net/dearsq/article/details/70175637 Platform: RK3399 OS: Android 6.0 Kernel ... 
- POJ2135 Farm Tour —— 最小费用最大流
			题目链接:http://poj.org/problem?id=2135 Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submis ... 
