cf459C Pashmak and Buses
1 second
256 megabytes
standard input
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.
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 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.
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.
题意是有长度为n的序列,然后要在序列中填1到k的数做d次,使得序列中不存在两个位置在d次中都填一样的数。输出一组方案
然后orz了不知名的神犇才会……看样子好像是类似分治的做法……就是尽量n个位置平均分配1到k,然后变成1 2 3 4 5……k 1 2 3 4 5……k的样子,然后倒着做,变成1 1 1 1 1……2 2 2 2 2…… 3 3 3 3 ……的样子
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int ans[2333][2333]; int main()
{
int i,j,k,m,n,d,delta,l,r;
scanf("%d%d%d",&n,&k,&d);
delta=1;
for(i=1;i<=d;i++)
{
for(j=1;j<=n;j++)
{
ans[i][j]=1;
}
}
for(i=1;i<=d;i++)
{
delta*=k;
if(delta>=n)
{
for(j=2;j<=n;j++)
{
l=i;
while(ans[l][j-1]==k)
{
l--;
}
for(r=1;r<=l;r++)
{
ans[r][j]=ans[r][j-1];
}
ans[l][j]++;
}
for(i=1;i<=d;i++)
{
for(j=1;j<=n;j++)
{
printf("%d ",ans[i][j]);
}
printf("\n");
}
return 0;
}
}
printf("-1\n");
return 0;
}
cf459C Pashmak and Buses的更多相关文章
- 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 打印全排列
这题假设将终于的结果竖着看,每一列构成的数能够看成是k进制的数.一共同拥有d列,随意两列都不同样,所以这就是一个d位k进制数全排列的问题,一共同拥有k ^ d个排列.假设k ^ d < n,则打 ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 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安 ...
- codeforce Pashmak and Buses(dfs枚举)
/* 题意:n个同学,k个车, 取旅游d天! 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 也就 ...
- codeforces 459C Pashmak and Buses(模拟,组合数A)
题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...
- Codeforces Round #261 (Div. 2)——Pashmak and Buses
题目链接 题意: n个人,k个车,d天.每一个人每天能够坐随意一个车.输出一种情况保证:不存在两个人,每天都在同一辆车上 (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). 分析: 比赛中 ...
随机推荐
- PASCAL的优越性:官方的说法(不需要Makefile,节约大量的时间)
也许你认为为什么我选择pascal代替其他的语言,像C.或者您会拿FreePascal和其他的pascal编译器作比较,那么好,这里您看看FreePascal为什么好: 1.pascal是一个非常简洁 ...
- FileMode枚举
FileMode枚举是一个简单枚举,用于指定操作系统打开文件的方式. 枚举成员 成员值 描述 CreateNew 1 指定操作系统应创建新文件,如果文件存在则引发异常. Create 2 指定操作系统 ...
- hdu 4501 小明系列故事——买年货_二维背包
题目:你可以有v1元,v2代金券,v3个物品免单,现在有n个商品,商品能用纸币或者代金券购买,当然你可以买v3个商品免费.问怎么最大能买多少价值 题意: 思路二维背包,dp[v1][v2][v3]=M ...
- Mod_python: The Long Story
mod_python: the long story - Grisha Trubetskoy Mod_python: The Long Story Oct 25th, 2013 | Comments ...
- H5单页面架构:自定义路由 + requirejs + zepto + underscore
angular优点: 强大的数据双向绑定 View界面层组件化 内置的强大服务(例如表单校验) 路由简单 angular缺点: 引入的js较大,对移动端来说有点吃不消 语法复杂,学习成本高 backb ...
- Oracle Linux Server 7安装VMwareTools问题
OracleLinuxServer7安装VMwareTools问题#./vmware-install.pl时报错:#-bash: ./vmware-instal.pl:/usr/bin/perl:ba ...
- SQL Performance Improvement Techniques(转)
原文地址:http://www.codeproject.com/Tips/1023621/SQL-Performance-Improvement-Techniques This article pro ...
- react学习之props
中秋过后刚好结束在上一家公司的工作,明天开始要正式的找工作了,最近也投了几家公司收到几分面试邀请.在面试的过程中几个面试官聊到了react(当然也有聊了vue,angular).感觉不懂react都不 ...
- rotate.js实现图片旋转 (chrome,IE,firefox都可以实现)
找了好多资料,要么是IE可以用,但是谷歌不行,,还有就是两个都可以用的,图片大小显示不全.终于找到一个好一点的js,先贴一下代码. 1.rotate.js jQuery.fn.rotate = fun ...
- Android 使用网络ADB调试.
前提: android Phone和PC在同一局域网内. android Phone 有虚拟终端(CM系统集成了ADB网络调试,比较赞.); 1.在android phone虚拟终端输入 stop a ...