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 ...
随机推荐
- perforce 使用教程(zz)
http://www.perforce.com/documentation/perforce_technical_documentation http://blog.csdn.net/brucexu1 ...
- PHP的代理模式
php的代理模式的实现: 理解一种模式,可以融会贯通,和其它的模式进行对比.找出为什么要 代理模式呢?跟父类.接口的区别是什么? 为什么需要这种模式?存在的价值? 原文:https://www.cnb ...
- JVisualVM简介与内存泄漏实战分析
JVisualVM简介与内存泄漏实战分析 学习了:https://blog.csdn.net/kl28978113/article/details/53817827
- Grunt的配置及使用(压缩合并js/css)
Grunt的配置及使用(压缩合并js/css) 安装 前提是你已经安装了nodejs和npm. 你能够在 nodejs.org 下载安装包安装.也能够通过包管理器(比方在 Mac 上用 homebre ...
- android 开源组件合集-UI篇(2013-11-07更新)
其实也算不上合集,只是将我经常用到的部分整理一下,如果您有好东西,也可以留言补充 1.actionbar http://actionbarsherlock.com/ https://github.co ...
- [置顶] ArcGIS Runtime SDKs 10.2 for iOS & Android& OS X发布
我们高兴的宣布:ArcGISRuntime SDKs 10.2 for iOS & Android & OS X正式发布!在10.2版本中,你可以在iOS.Android和Mac设备上 ...
- Hadoop HelloWord Examples -对Hadoop FileSystem进行操作 - 基于Java
我之前对hadoop的各种文件操作都是基于命令行的,但是进阶后,经常需要直接从java的代码中对HDFS进行修改.今天来练习下. 一个简单的demo,将hdfs的一个文件的内容拷贝到另外hdfs一个文 ...
- vue - 减少打包后的体积
打包命令: npm:npm run build yarn:yarn run build 路径:/config/index.js 是否产生map文件,置为false.
- 定义JQuery插件
http://cavalry800528.iteye.com/blog/1953917 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$( ...
- 查看正在执行的sql语句
;WITH t AS( SELECT [Spid] = session_Id, ecid, [Database] = DB_NAME(sp.dbid), [User] = nt_username, [ ...