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, ...
随机推荐
- curl 做爬虫 用服务器代理ip
有时候会ip会封锁,所以会用一些模拟代理ip进行抓取测试 从网上找了一下代码 function curl_string ($url,$user_agent,$proxy){ $ch = ...
- 数据结构之链式队列(C实现)
1.1 linkqueue.h #ifndef LINKQUEUE_H #define LINKQUEUE_H #include <stdio.h> #include <mallo ...
- VMWare虚拟网络编辑
VMWare虚拟网络编辑记录. 点击"编辑->虚拟网络编辑器" 在网卡列表中选择"VMnet8"查看目前设置,点击右下角的更改设置进行网络修改. 备注:更 ...
- EditText(8)EditText中drawableRight图片的点击事件
参考: http://stackoverflow.com/questions/3554377/handling-click-events-on-a-drawable-within-an-edittex ...
- 387 First Unique Character in a String 字符串中的第一个唯一字符
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1.案例:s = "leetcode"返回 0.s = "loveleetcode&qu ...
- msxml3.dll 错误 '800c0005' 系统错误: -2146697211。
asp网站 因为这个问题,困扰自己好多次,还重装过两次服务器系统,非常的麻烦,这次终于找到了问题所在,记录下来,方便以后查看. 服务器症状: 1.服务器上的IE浏览器不能访问外网: 2.set htt ...
- nginx connect failed (110- Connection timed out) 问题排查
首先排查 ping 下 nginx 与代理服务是否ping 的通,带端口的,telnet 下端口号是否是通的,本次遇到问题为 telnet 发现有台服务器不通,原因是端口未开放
- dubbo与springmvc的简单使用
什么是Dubbo? dubbo是阿里巴巴公司开源的高性能优秀服务框架,通过高性能的RPC(远程服务调用)实现服务的输入输出功能,可以与spring框架无缝整合: 传统的架构所有的模块都在一台服务器上, ...
- 利用eclipse调试JDK源码
先看效果图 综合网上各种教程,总结如下 新建 D:/jdk/src .D:/jdk/debug 目录 src存放源码 debug存放编译结果 将 %JAVA_HOME%/src.zip 解压到 D:/ ...
- 梦想MxWeb3D,三维CAD协同设计平台 2019.05.05更新
SDK开发包下载地址: http://www.mxdraw.com/ndetail_20140.html 在线演示网址: http://www.mxdraw.com:3000/ 1. 增加CAD绘图 ...