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 ...
随机推荐
- QT中进度条的使用
在QT中可以用QProgressBar或着QProgressDialog来实现进度条. QProgressBar的使用 首先在designer中拖一个按钮和进度条部件,按下面初始化 //补充:下面两句 ...
- 轮播图插件myFocus使用
myFocus官网下载源码,本文是v2.0.1版,解压后如下 将js包内文件拷入工程 在工程内引入 <script src="js/myfocus-2.0.1.min.js" ...
- windows常用环境变量
%ALLUSERSPROFILE%列出所有用户Profile文件位置. %APPDATA%列出应用程序数据的默认存放位置. %CD%列出当前目录. %CLIENTNAME%列出联接到终端服务会话时客户 ...
- java 操作配置文件 .properties
package com.dms.common; import java.io.File; import java.io.FileInputStream; import java.io.FileNotF ...
- git多人协作
多人协作 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ ...
- 分析Ext2文件系统结构。
1. 目的 分析Ext2文件系统结构. 使用 debugfs 应该跟容易分析 Ext2文件系统结构 了解ext2的hole的 2. 准备工作 预习文件系统基本知识: http://www.doc88. ...
- 特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN
特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN 特卖电商俏物悄语或面临破产 ihush域名夭折?
- iphone5升级到iOS7时出现“This device isn't eligible for the requested build”错误
因为工作的需要我需要把自己的手机升级到iOS7,安装苹果的升级顺序总是报This device isn't eligible for the requested build错误,搜索相关的文章我的错误 ...
- dom4j和jaxp解析工具的
dom4j解析中的几个对象 node --branch --document --element --commment --attribute --text branch --document --e ...
- C# SQL文件执行器的功能实现
好一段时间没写博客了,这次我们来一起谈谈SQL文件执行器的功能实现,在ERP软件升级时往往在客户端程序更新的同时也要对数据库进行升级,ERP程序开发人员会对数据库升级的执行代码在开发的过程中以SQL文 ...