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). 分析: 比赛中 ...
随机推荐
- QObject就有eventFilter,功能很强(随心所欲的进行处理,比如用来QLineEdit分词)
相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! 基于 ...
- SqlBulkCopy 类
1.SqlBulkCopy 简介 Microsoft SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具,用于将数据从一个表移动到另一个表(表既可以在同一个服务器上,也可以在不同 ...
- 【转】 怎么刷入BOOT.IMG(刷机后开机卡在第一屏的童鞋请注意)-------不错不错
原文网址:http://bbs.gfan.com/android-3440837-1-1.html 之前呢,有好多机油问我关于刷机卡屏的问题,我解答了好多,但一一解答太费事了,在这里给大家发个贴吧.其 ...
- 【转】基于V4L2的视频驱动开发
编写基于V4L2视频驱动主要涉及到以下几个知识点:1> 摄像头方面的知识 要了解选用的摄像头的特性,包括访问控制方法.各种参数的配置方法.信号输出类型等.2> Camera解码器.控制器 ...
- 自定义View的封装
通过上一个博文的自定义View的编写后,发现代码其实挺复杂的,所有这里通过对代码进一步的优化,即用到了java的一个重要的特点:封装.通过对父类的方法进行封装,然后在子类继承后实现相应的函数即可,达到 ...
- UVA 1599 Ideal Path(bfs1+bfs2,双向bfs)
给一个n个点m条边(<=n<=,<=m<=)的无向图,每条边上都涂有一种颜色.求从结点1到结点n的一条路径,使得经过的边数尽量少,在此前提下,经过边的颜色序列的字典序最小.一对 ...
- jquery实现仿商品星级评价
一,HTML部分 <div id="rating-star"> <a href="#">0</a> < ...
- jquery工具
http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxsplitter/jquery-splitter-gett ...
- 2014年百度之星资格赛第三题Xor Sum
Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheus 将向 Zeu ...
- Qt 信号与槽
Qt信号与槽的理解 信号和槽机制是 QT 的核心机制,要精通 QT 编程就必须对信号和槽有所了解.信号和槽是一种高级接口,应用于对象之间的通信,它是 QT 的核心特性,也是 QT 区别于其它工具包的重 ...