cf 459c Pashmak and Buses
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
The first line of input contains three space-separated integers n, k, d(1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).
Output
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.
Sample Input
3 2 2
1 1 2
1 2 1
3 2 1
-1
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<fstream>
#include<cstring>
using namespace std;
int code[][];
int main()
{
int n,k,d;
//cout<<1000*log10(1000000000+0.0)<<endl;
//cout<<pow(5,4)<<endl;
while(~scanf("%d%d%d",&n,&k,&d))
{
int tmp;
int flag=k;
for(int i=;i<d-;i++)
{
if(flag>n) break;
flag*=k; }
//cout<<flag;
if(flag<n)
{
printf("-1\n");
continue;
}
tmp= (pow(n+0.0,1.0/d)>(int)pow(n+0.0,1.0/d))?(int)pow(n+0.0,1.0/d)+:(int)pow(n+0.0,1.0/d);
for(int j=;j<d;j++)
code[j][]=code[j][]=;
for(int i=; i<n; i++)
{
int j=d-; //cout<<"ss";
code[j][i]++;
int now=code[j][i];
int row=j;
int col=i;
while(now>tmp-&&row>-)
{
code[row][col]=now%(tmp);
code[row-][col]+=(now/(tmp));
now=code[row-][col];
row--;
}
for(int j=;j<d;j++)
code[j][i+]=code[j][i];
}
for(int i=; i<d; i++)
{
for(int j=; j<n; j++)
{
cout<<code[i][j]+<<" ";
}
cout<<endl;
}
}
return ;
}
这里
for(int i=0;i<d-1;i++)
{
if(flag>n) break;
flag*=k;
}
如果用pow的话,存在两个问题:1 pow(1e9,1000)过大 2 由于精度问题,有些数的比较是失败的
cf 459c Pashmak and Buses的更多相关文章
- CodeForces - 459C - Pashmak and Buses
先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...
- 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 #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- CF 459A(Pashmak and Garden-正方形给出2点求2点)
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- INFORMATICA 的元数据管理之二:运行状态信息查询
本项目里的两个哥们做的关于运行状态元数据的两个JOB挺酷的,最近一段时间运行状况良好,自己参考学习的同时以做日志记载,呵呵,为了节省笔墨,相关元数据表结构以及MAPPING设计之类不做介绍(如有疑问欢 ...
- IE6支持min-width、max-width CSS样式属性
1.IE6支持max-width解决方法 IE6支持最大宽度,解决CSS代码: .yangshi{ max-width:1000px; _width:expression((document.docu ...
- mssql Sqlver 修改标识列方法
摘自: http://www.cnblogs.com/badboy2008/articles/1145465.html MSSQL Server修改标识列方法 ----允许对系统表进行更新exec ...
- DRP——JDBC中的Batch
在jdbc2.0里添加了批量处理的功能(batch),其同意将多个sql语句作为一个单元送至数据库去运行,这样做能够提高操作效率.在操作大量的数据时, ORM框架实现批量是非常慢的.我们能够使用jdb ...
- ganglia组播和单播
ganglia快速开始向导(翻译自官方wiki) 发布于 2012 年 1 月 23 日 由 admin 2 comments发表评论 转自:http://cryinstall.com/?p=18 ...
- POJ 2823 UESTCoj 1221 Sliding Window 单调队列 经典入门题
题意:给出一个序列,求出每连续k个数字中最大的数和最小的数. 这是道单调队列裸题,直接写就行了. 本来用deque写出来后,发现在poj上硬是超时了,在discuss上看很多人也在抱怨超时的问题,据说 ...
- Java程序实现密钥库的维护
1 Java程序列出密钥库所有条目 import java.util.*; import java.io.*; import java.security.*; public class ShowAli ...
- javascript 面向对象编程(工厂模式、构造函数模式、原型模式)
javascript 面向对象编程(工厂模式.构造函数模式.原型模式) CreateTime--2018年3月29日17:09:38 Author:Marydon 一.工厂模式 /** * 工厂模 ...
- js&jquery避免报错的方法
CreateTime--2016年12月8日15:28:40Author:Marydonjs&jquery规避报错信息的两种方式 <script type="text/ja ...
- 揭秘ThreadLocal(转)
转载自:掘金大闲人柴毛毛博客. ThreadLocal是开发中最常用的技术之一,也是面试重要的考点.本文将由浅入深,介绍ThreadLocal的使用方式.实现原理.内存泄漏问题以及使用场景. Thre ...