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:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ...
随机推荐
- vue 安装与起步
vue安装: 1.官网下载vue,在script标签里引用(去下载) 2.使用CDN(建议下载到本地,不推荐这种方法): BootCDN:https://cdn.bootcss.com/vue/2.2 ...
- 简单的dp hdu 数塔(水题)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- 设计模式学习笔记——Decorator装饰模式
装饰模式的作用或动机就是,尽量避免继承,而使用关联.原因是层层继承下来,内容会越来越多,有失控的危险.就扩展性而言,用关联比用继承好.所谓的关联,A使用了B,就叫A关联了B. Component 抽象 ...
- CSS3 弹性盒子(Flex Box) 微信小程序图片通栏
{{define "chkUrl"}} <!DOCTYPE html><html lang="zh-cmn-Hans"><head ...
- mysql 查询表死锁 和结束死锁的表步骤以及锁表等级
1.查询是否锁表show OPEN TABLES where In_use > 0; 2.查询进程 show processlist 查询到相对应的进程===然后 kill id 补充: ...
- android user 版本如何默认adb调试为打开【转】
本文转载自:http://blog.csdn.net/chaihuasong/article/details/50342119 A. 软件准备 user版本需要先打开USB debug开关,打开方式如 ...
- POJ2752 Seek the Name, Seek the Fame —— KMP next数组
题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Li ...
- YTU 2443: C++习题 复数类--重载运算符3+
2443: C++习题 复数类--重载运算符3+ 时间限制: 1 Sec 内存限制: 128 MB 提交: 1368 解决: 733 题目描述 请编写程序,处理一个复数与一个double数相加的运 ...
- 自定义UITabBarController
用的时候直接拷贝代码即可. 1.在AppDelegate设置跟控制器为:PQTabBarController #import "PQTabBarController.h" @int ...
- BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP
BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP Description Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的 ...