CodeForces - 459C - 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个人,k辆车,d个景点,现在要求每个学生每天去一个景点(一共d天)每选一个景点去的时候需要坐某一辆车,现要求这d天里面,没有任意两个人是都坐在同一辆车里面(不能d天都都在一起)。
做法:一开始我想的是从k辆车里面选d辆,然后将n个学生分配进去,但是这样做好像不行。后来就换了个思路,从k辆车里面选d辆车(可重复)作为某一个学生这d天的乘车方案,然后将这些排列的其中n个求出来就可以了。当然,如果没有这么多的话就输出-1。
上代码:
#include <bits/stdc++.h>
#define ll long long
#define MAX 1002
using namespace std; ll n,k,d;
ll s[MAX][MAX];
ll arr[MAX],now; bool check(){
ll ans=;
for(ll w=d;w>;w--){
ans=ans*k;
if(ans>=n) return ;
}
return ;
} bool cons(int tot){
if(tot==d){
for(int i=;i<tot;i++){
s[i][now]=arr[i];
}
now++;
if(now==n) return ;
return ;
}
for(int i=;i<=k;i++){
arr[tot]=i;
if(cons(tot+)) return ;
}
return ;
} void print(){
for(int i=;i<d;i++){
for(int j=;j<n;j++){
if(j) cout<<" ";
cout<<s[i][j];
}
cout<<endl;
}
} int main()
{
//freopen("data.txt","r",stdin);
ios::sync_with_stdio(false);
while(cin>>n>>k>>d){
if(check()){
memset(s,,sizeof(s));
now=;
cons();
print();
}else{
cout<<"-1"<<endl;
}
}
return ;
}
/*459C*/
CodeForces - 459C - Pashmak and Buses的更多相关文章
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- codeforces 459C Pashmak and Buses(模拟,组合数A)
题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...
- CodeForces 459C Pashmak and Buses(构造)题解
题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...
- Codeforces 459C Pashmak and Buses 机智数学题
这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- 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
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
随机推荐
- (数论)51NOD 1079 中国剩余定理
一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K.例如,K % 2 = 1, K % 3 = 2, K % 5 = 3.符合条件的最小的K = 23. Input 第1行:1个数 ...
- 【题解】TES-Intelligence Test
[题解]\(TES-Intelligence\) \(Test\) 逼自己每天一道模拟题 传送:\(TES-Intelligence\) \(Test\) \([POI2010]\) \([P3500 ...
- 基于.Net Core的API框架的搭建(4)
6.加入日志功能 日志我们选用log4net,首先引入程序包: 选择2.0.8版本安装.然后在项目根目录新增log4net的配置文件log4net.config: <?xml version=& ...
- 启动tomcat报错:ImageFormatException
启动某工程报错: java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/ImageFormatException 查找此类存在于jdk的rt ...
- [ TJOI 2010 ] 打扫房间
\(\\\) Description 给出一个\(N\times M\) 的网格,一些格子是污点,求是否能用多个封闭的环路覆盖所有不是污点的格点. 封闭的环路覆盖的含义是,每条路径都必须是一个环,且每 ...
- Object.assign() 对象的扩展
object.assign()方法用于对象的合并,将源对象的(source)的所有的可枚举属性,复制到目标对象(target) var target = {a:1}; var source1={b:2 ...
- windows 下完全卸载service
用SC Delete命令的话,如果服务名称中带空格,则请在服务名称前面用半角的双引号括起,如SC delete "Adobe LM Service",另外Services这个子键一 ...
- C++为什么抓不到除0错“异常”?
http://blog.csdn.net/nanyu/article/details/6475555 有人问这个问题: try { std::cout << 10/0 << s ...
- RocketMQ学习笔记(16)----RocketMQ搭建双主双从(异步复制)集群
1. 修改RocketMQ默认启动端口 由于只有两台机器,部署双主双从需要四个节点,所以只能修改rocketmq的默认启动端口,从官网下载rocketmq的source文件,解压后使用idea打开,全 ...
- ThinkPHP---案例2--部门管理功能
[一]部门列表展示 分析: ①控制器DeptController.class.php ②方法showList(不要使用list方法,因为list是关键词) ③模板文件:showList.html 下面 ...