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. Openwrt WIFI探针开发【一】

    2017.9.26 公开源码(Apache2.0协议) https://github.com/769484623/WiFiProbe ————————————————————————————————— ...

  2. Android面试,BroadCastReceiver的两种注册方式的异同

    在Android手机应用程序中开发中,需要用到BroadcastReceiver来监听广播的消息.在自定义好BroadcastReceiver ,需要对其进行注册,注册有两种方法: 一种是在代码当中注 ...

  3. WeifenLuo.WinFormsUI.Docking添加关闭功能

    /****************************************************************** * 创建人:HTL * 创建时间:2014-7-8 15:37: ...

  4. JAVA:连接池技术说明以及MVC设计模式理解

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjgzMDgwNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  5. 从HttpServletRequest获取完整的请求路径

    String url = request.getRequestURI(); // 这个方法只能获得不包含参数的请求url,且只包含相对路径 StringBuffer url_buffer = requ ...

  6. leetCode 86.Partition List(分区链表) 解题思路和方法

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  7. Edit Control响应全选(Ctrl+A)

    MFC中的Edit控件用于输入数据,当输入的数据为大段数字的时候,全选功能就显得非常重要了,可偏偏在MFC中Edit控件就不 支持全选.Ctrl+A不行,双击也不行. Ctrl+C和Ctrl+V都是默 ...

  8. java程序设计题库

    选择题 答题要求:单选题,每题只有一个正确答案,选择正确给分,不正确不给分. 1. 下面(   A    )数据类型可用于main()方法中传递的参数 A.String   B.Integer   C ...

  9. Python方法完成农历日历功能代码

    来自 #coding=utf-8 #****************************************************************************** # 下 ...

  10. Java之JVM调优案例分析与实战(1) - 高性能硬件上的程序部署策略

    本JVM系列均来源于<深入理解Java虚拟机>一书中,版权归该书作者所有. 环境:一个15万PV/天左右的在线文档类型网站最近更换了硬件系统,新系统硬件为4个CPU.16GB物理内存.OS ...