E - 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

Input
3 2 2
Output
1 1 2 
1 2 1
Input
3 2 1
Output
-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的更多相关文章

  1. CodeForces - 459C - Pashmak and Buses

    先上题目+: C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. codeforces 459C Pashmak and Buses 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...

  3. codeforces 459C Pashmak and Buses(模拟,组合数A)

    题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostre ...

  4. CodeForces 459C Pashmak and Buses(构造)题解

    题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...

  5. Codeforces 459C Pashmak and Buses 机智数学题

    这个题目说的是有n个人,有k辆巴士,有m天,每天都要安排n个人坐巴士(可以有巴士为空),为了使得这n个人不会成为朋友,只要每两个人在这m天里坐的巴士至少一天不相同即可. 要你求是否有这样的安排方法,如 ...

  6. 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 ...

  7. cf459C Pashmak and Buses

    C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  9. 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 ...

随机推荐

  1. INFORMATICA 的元数据管理之二:运行状态信息查询

    本项目里的两个哥们做的关于运行状态元数据的两个JOB挺酷的,最近一段时间运行状况良好,自己参考学习的同时以做日志记载,呵呵,为了节省笔墨,相关元数据表结构以及MAPPING设计之类不做介绍(如有疑问欢 ...

  2. java后台与jsp前台特殊字符处理(字符串编码与解码)

    在后台与前台数据交互时如果有特殊字符就很容易出现问题,所以就需要对字符串进行编码传输,在获取后再进行解码: 1.Java后台进行编码与解码 URLEncoder.encode(str,"ut ...

  3. java学习笔记13--反射机制与动态代理

    本文地址:http://www.cnblogs.com/archimedes/p/java-study-note13.html,转载请注明源地址. Java的反射机制 在Java运行时环境中,对于任意 ...

  4. Android -- 发送Broadcast、有序无序

    普通广播                                                                                     优缺点:和有序广播的优 ...

  5. 【Python】《大话设计模式》Python版代码实现

    <大话设计模式>Python版代码实现 上一周把<大话设计模式>看完了,对面向对象技术有了新的理解,对于一个在C下写代码比较多.偶尔会用到一些脚本语言写脚本的人来说,很是开阔眼 ...

  6. 鼠标辅助点击器(MouseClickAidHelper)

    鼠标辅助点击器(MouseClickAidHelper) 下载地址:http://www.endv.cn/product/view28.html 由天云信息开发,并已开源,功能无限制,软件解决了重复操 ...

  7. 设计模式之Programming to an Interface, not anImplementation 程序指向接口,而不是实现

    Class inheritance is basically just a mechanism for extending an application's functionality by reus ...

  8. 微信小程序 - 选取搜索地点并且显示(map)

    演示如下,使用时,你也许会配合它:腾讯地图路线规划 wxml: <view class='address' bindtap='onChangeAddress'> <input cla ...

  9. 自己定义UIView以实现自绘

    有时候我们须要自绘uiview以实现自己的需求,比方依据坐标点绘制出连续的曲线(股票走势图),就须要自绘uiview了. 原理:继承uiview类(customView),并实现custom view ...

  10. 【Linux】cd命令

    用途 cd命令的主要作用是变换目录 全称 cd的全称是Change Directory   案例 以下是一些基础的cd命令操作(酒红色字体为命令 ,蓝色字体为解释字体) [root@bigdata ~ ...