题目地址:http://codeforces.com/contest/459/problem/C

C. Pashmak and Buses
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

Output

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.

Sample test(s)
input
3 2 2

output
1 1 2
1 2 1

input
3 2 1

output
-1

Note

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^d种。假设要输出的话,最简单的方法就是进行全排列呗。。。。

要注意。。

假设用的跟我的求全排列方法一样的话。那须要注意中间的cnt值是会非常大的。可是由于最多仅仅须要输出n种,所以假设大于n的话就直接让他等于n+1。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>using namespace std;
#define LL __int64
LL mp[3100][3100];
int main()
{LL n, k, d, i, j, cnt, h, flag=0, x, y;scanf("%I64d%I64d%I64d",&n,&k,&d);memset(mp,0,sizeof(mp));cnt=1;for(i=1;i<=d;i++){for(j=1;j<=n;j++){if((j-1)%cnt==0){mp[i][j]=mp[i][j-1]+1;if(mp[i][j]>k){mp[i][j]=1;if(i==d){flag=1;break;}}}elsemp[i][j]=mp[i][j-1];}if(j!=n+1)break;cnt*=k;if(cnt>1000)cnt=1001;}if(flag){printf("-1\n");}else{for(i=d;i>=1;i--){for(j=1;j<=n;j++){printf("%I64d ",mp[i][j]);}printf("\n");}}return 0;
}

转载于:https://www.cnblogs.com/lcchuguo/p/5183995.html

codeforces #261 C题 Pashmak and Buses(瞎搞)相关推荐

  1. HDU 4923 Room and Moor(瞎搞题)

    瞎搞题啊.找出1 1 0 0这样的序列,然后存起来,这样的情况下最好的选择是1的个数除以这段的总和. 然后从前向后扫一遍.变扫边进行合并.每次合并.合并的是他的前驱.这样到最后从t-1找出的那条链就是 ...

  2. 简单瞎搞题 动态规划的优化

    链接:登录-专业IT笔试面试备考平台_牛客网 来源:牛客网 题目描述 一共有 n个数,第 i 个数是 xi xi 可以取 [li , ri] 中任意的一个值. 设 S=∑xi2S = \sum{{x_ ...

  3. Wannafly交流赛1: C. 腰带图(瞎搞)

    链接:https://www.nowcoder.com/acm/contest/69/C 来源:牛客网 题目描述 一个n个点m条边的无向图,它若满足以下性质,我们就称它为腰带图: 1.n为>=6 ...

  4. [JZOJ5281]钦点题解--瞎搞+链表

    [JZOJ5281]钦点题解--瞎搞+链表 题目链接 于 暴 力 过 分析 第一眼: 模拟美滋滋?! 然后数据范围...不太对 naiive模拟30pts 然后你交换字符串指针60pts 然后发现可以 ...

  5. android重置系统,安卓手机越用越卡,恢复出厂设置真有用?别瞎搞,看完就明白了!...

    安卓手机越用越卡,恢复出厂设置真有用?别瞎搞,看完就明白了! 现在手机的价格逐渐的开始上升,一部好一点的手机价格还是比较贵的,所以很多人想要节省更多的换机支出,都会想要购买到一款可以使用的比较久的手机 ...

  6. HDU5971【瞎搞】

    题意:略(忙着准备文化课...明天期中考啊.... 思路: 正解就是染色,2-sat搞: AC代码(虽然是错误的...数据水(过踏马的也行啊,起码打脸他啊!) 4 3 1 0 1 2 2 3 3 4 ...

  7. HDU 5600(瞎搞)

    第一场Bestcoder居然爆零..果然是too naive..小聪明全部直接输出"YES"过了pretest,结果被叉也是&%$% 找到规律传递下就好.后来看官方题解感觉 ...

  8. 别再瞎搞数仓了!BAT内部大神:数据仓库不是谁都可以建的

    在我没有进互联网之前,我一直以为数据仓库是所有企业进行数据资产管理的必备工作,但直到我去了很多家企业搞数据之后才发现,原来并不是所有的企业都适合做数据仓库,更不要说数据中台了. 很多企业现在做数据仓库 ...

  9. 我的瞎搞开发工具集以及对一些工具的比较

    本文的目的是作为一个记录,不引战,同时为有同样瞎搞爱好者提供一个学习思路--尽量全部推荐和使用免费开源工具,减少版权纠纷,降低学习成本,大概算有用吧 我的技术栈: 实际上有很多并不是很熟,请酌情参考 ...

最新文章

  1. 如何对比_潭酒红潭酱酒对比红花郎怎么样口感如何
  2. Hadoop详解(四):HDFS shell操作和Java API操作
  3. 实战绕过宝塔PHP disable_function 限制getshell
  4. Azure pipeline 配置根据条件执行脚本
  5. 红橙Darren视频笔记 builder设计模式+navigationBar导航条
  6. 一个文件合成器的代码
  7. 【数据结构与算法】算法的时间复杂度
  8. spring boot的学习(1)杂
  9. 优化器,sgd,adam等
  10. proteus元件图片_Proteus模型,元件库
  11. easydarwin ffmpeg
  12. 个人信息安全规范----3、个人信息的收集、存储、使用
  13. MacBook Pro 上网很慢
  14. Arduino 控制RFID读写器读写 IC卡
  15. Q_01_04 量子比特
  16. 『转』饯行:理想主义终结年代的七种兵器
  17. 易盾php,PHP接入网易易盾验证码
  18. 为App签名(为apk签名)
  19. git删除目录下的所有文件并提交
  20. 看看美国人怎么做SEO

热门文章

  1. 品牌为Synaptics的触控板如何外接鼠标后自动禁用触控板
  2. 适合centos7 64位虚拟机添加硬盘 详细 步骤
  3. 全球首款采用华为鸿蒙系统的,首款鸿蒙系统终端新闻 华为正式发布鸿蒙系统...
  4. Elasticsearch常用术语
  5. Android Studio 常见报错
  6. mysql数据库 when_mysql case when怎样运用?_数据库
  7. 网页爬虫之cookie自动获取
  8. 冀欧速 OSA-25 王字壳氨气传感器壁挂式
  9. sdk_chip_ch2601库介绍
  10. CSS3+HTML蜡烛燃烧动画