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 ...
随机推荐
- 解决Robotium测试用例crash问题
今天遇到一个棘手的问题 用robotium框架真机测试客户端时 跑到一半会crash 搜了一堆资料终于解决了 我的程序引起crash主要原因有两个: 1.用Robotium测试框架跑多个用例(写在同一 ...
- C/C++代码静态检查工具Cppcheck在VS2008开发环境中的安装配置和使用
Cppcheck is an analysis tool for C/C++code. Unlike C/C++ compilers and many other analysis tools, it ...
- Java用Dijkstra算法实现地图两点的最短路径查询(Android版)
地图上实现最短路径的查询,据我了解的,一般用Dijkstra算法和A*算法来实现.由于这是一个课程项目,时间比较急,而且自己不熟悉A*算法,所以参考网上的Dijkstra算法(http://blog. ...
- oracle解锁表
select b.owner,b.object_name,a.session_id,a.locked_mode,c.serial#,c.sid||','||c.serial# from v$locke ...
- centos扩容(pv,vg,lv)
preFace: (应用场景需求分析)
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn
这个异常我在网上查看了很多资料,一般都说是hibernate的session问题,让重新两个方法,但是我以前用的时候没问题啊,所以一直找问题,终于这个bug让我找到了,就是因为我插入操作的时候用的是别 ...
- PLSQl远程连接oracle数据库
PLSQL远程连接Oracle 10G 1.在安装ORACLE服务器的机器上搜索下列文件, ORACLE 服务器上的文件 oci.dll ocijdbc10.dll ociw32.dl ...
- http 双向通信之port映射
新产品开发了近2-3个月,给到客户做试用的时候,发现一个开发这么久从未考虑到的一个通信问题,mark下,下次开发同类产品的时候长点记性了. 产品由client与服务端两部分组成,client与服务端须 ...
- Effective C++ 条款11
在operator=中处理"自我赋值" 什么是自我赋值,非常明显. 就是自己的值赋值给了自己.以下的代码就是自我赋值: class Widget { public: Widget& ...
- 大型票务系统中username和password的安全性问题
讨论请移步至:http://www.zhiliaotech.com/ideajam/idea/detail/307 相关文章: <今天你买到票了吗?--从铁道部12306.cn站点漫谈电子商务站 ...