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. 跨平台app开发(引擎)工具的选择

    1.html5执行速度慢,用户体验不好 2.原生应用开发,即ios和安卓分别开发,需要两种技术人员,后期代码维护困难,很难达到统一. 3.xamarin是一款c#的解决方案,收费.xamarin.fo ...

  2. Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程) 分类:Androidandroid实例

    1.当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vie ...

  3. 设置pycharm为Eclipse快捷键

    Ctrl + O 根据name模糊查找当前文件中类.方法Alt + (向左箭头或者向右箭头) ,回退or前进到到之前查看或者编辑处Alt + (向上箭头或者向下箭头) ,将当前方法整体往下或者往上移动 ...

  4. Android -- ContentProvider与联系人

    数据库                                                                                         读联系人 raw ...

  5. Thinkphp学习笔记-删除缓存

    Thinkphp的缓存数据在Cach文件夹下的Home文件夹下的文临时文件 清除方法:将缓存文件删除就可以了

  6. 【Python】【Nodejs】下载单张图片到本地,Python和Nodejs的比较

    Python版本: # 下载单张图片到本地,看用时多少 import urllib.request import datetime starttime = datetime.datetime.now( ...

  7. python xlrd简单读取excel

    import xlrd #打开文件 book = xlrd.open_workbook ('Status.xlsx') #获取数据表 table1 = book.sheets()[0] table2 ...

  8. 使用Bundle进行VIM插件的管理

    http://www.oschina.net/p/vundle git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle ...

  9. Spring Boot学习记录(二)–thymeleaf模板

    自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...

  10. 算法笔记_037:寻找和为定值的两个数(Java)

    目录 1 问题描述 2 解决方案 2.1 排序夹逼法   1 问题描述 输入一个整数数组和一个整数,在数组中查找两个数,满足他们的和正好是输入的那个整数.如果有多对数的和等于输入的整数,输出任意一对即 ...