codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C
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.
这题就是求一全排列。由于要求每一天的都不同样,所以最多是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;
}
}
}
else
mp[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;
}
codeforces #261 C题 Pashmak and Buses(瞎搞)的更多相关文章
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces Round #261 (Div. 2)——Pashmak and Buses
题目链接 题意: n个人,k个车,d天.每一个人每天能够坐随意一个车.输出一种情况保证:不存在两个人,每天都在同一辆车上 (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). 分析: 比赛中 ...
- HDU 4968(杭电多校#9 1009题)Improving the GPA (瞎搞)
题目地址:HDU 4968 这题的做法是全部学科的学分情况枚举,然后推断在这样的情况下是否会符合平均分. 直接暴力枚举就可以. 代码例如以下: #include <cstring> #in ...
- HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)
题目地址:HDU 4970 先进行预处理.在每一个炮塔的火力范围边界标记一个点. 然后对每一个点的伤害值扫一遍就能算出来. 然后在算出每一个点到终点的总伤害值,并保存下来,也是扫一遍就可以. 最后在询 ...
- Codeforces #261 D
Codeforces #261 D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per te ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- CodeForces - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
随机推荐
- C#BASE64 UTF8字符串加密解密
base 64 解码 base64 bb = new base64(); string orgStr= Encoding.Default.GetString(bb.GetDecoded("b ...
- 7.java.lang.IllegalAccessException
java.lang.IllegalAccessException 没有访问权限 当应用程序要调用一个类,但当前的方法即没有对该类的访问权限便会出现这个异常.对程序中用了Package的情况下要注意这个 ...
- 车间任务不允许"每个装配件"超过100000
应用 Oracle Work in Progress 层 Level Function 函数名 Funcgtion Name WIP_WIPMRMDF 表单名 Form Name WIPMRMDF ...
- U盘安装XP SP3 professional手记
因为专业应用的软件无法在win7上运行,但在XP上是可以正常使用,所以有想法并有必要重装一下. 说句实在话,之前用U盘安装Windows7真的没有这么麻烦,没想到相同的技术用于安装XP 却是如此折腾人 ...
- QT中代码中与设计器中控件信号与SLOT连接(原来还可以这样连接)
双击testqt.ui 托一个push button到窗体中,双击,可以输入字符 按F4或 menu->edit->edit signals/slots 定义SLOT 选择已定义好的SLO ...
- CentOS 删除自带的OpenJDK 和 安装SunJDK
[root@WX32 local]# java -version java version "1.6.0" OpenJDK Runtime Environment (build - ...
- oracle job 定时执行 存储过程
oracle job 定时执行 存储过程 一:简单测试job的创建过程案例: 1,先创建一张JOB_TEST表,字段为a 日期格式 SQL> create table JOB_TEST(a ...
- 04737_C++程序设计_第5章_特殊函数和成员
例5.1 分析下面程序中析构函数与构造函数的调用顺序. #include<iostream> using namespace std; class object { private: in ...
- Unity3D游戏开发从零单排(五) - 导入CS模型到Unity3D
游戏动画基础 Animation组件 Animation组件是对于老的动画系统来说的. 老的动画形同相应的动画就是clip,每一个运动都是一段单独的动画,使用Play()或CrossFade(),直接 ...
- 从零开始学习UNITY3D(GUI篇 2)
复合控件极其使用,toolbar,selectgrid 先看效果图: toolbar可以看作是一个button按钮的集合,一次只能点击一个按钮, selectgrid又可以堪称是一个toolbar的集 ...